diff --git a/api/maven-api-model/src/main/mdo/maven.mdo b/api/maven-api-model/src/main/mdo/maven.mdo
index 2829ffdc22..32fff55632 100644
--- a/api/maven-api-model/src/main/mdo/maven.mdo
+++ b/api/maven-api-model/src/main/mdo/maven.mdo
@@ -1315,6 +1315,15 @@
]]>
+
+ 4.0.0/4.0.99
+
+ public void clearManagementKey() {
+ managementKey = null;
+ }
+
+
+
diff --git a/api/maven-api-settings/src/main/mdo/settings.mdo b/api/maven-api-settings/src/main/mdo/settings.mdo
index 14ac0672b3..86c2820650 100644
--- a/api/maven-api-settings/src/main/mdo/settings.mdo
+++ b/api/maven-api-settings/src/main/mdo/settings.mdo
@@ -331,6 +331,10 @@
}
return profileMap;
}
+
+ public void setModelEncoding(String modelEncoding) {
+ update(getDelegate().with().modelEncoding(modelEncoding).build());
+ }
]]>
diff --git a/api/maven-api-toolchain/src/main/mdo/toolchains.mdo b/api/maven-api-toolchain/src/main/mdo/toolchains.mdo
index b8e2b1bbf8..4b90fd8ac8 100644
--- a/api/maven-api-toolchain/src/main/mdo/toolchains.mdo
+++ b/api/maven-api-toolchain/src/main/mdo/toolchains.mdo
@@ -102,6 +102,16 @@
+
+
+ 1.0.0/1.1.0
+
+ public void setModelEncoding(String modelEncoding) {
+ update(getDelegate().with().modelEncoding(modelEncoding).build());
+ }
+
+
+ ToolchainModel
diff --git a/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 5187a07774..28beaeb51c 100644
--- a/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -1425,10 +1425,9 @@ public class MavenCli {
}
if (modelProcessor != null) {
- return modelProcessor.locateExistingPom(current);
- } else {
- return current.isFile() ? current : null;
+ current = modelProcessor.locatePom(current);
}
+ return current.isFile() ? current : null;
}
// Visible for testing
@@ -1742,8 +1741,7 @@ public class MavenCli {
//
protected TransferListener getConsoleTransferListener(boolean printResourceNames) {
- return new SimplexTransferListener(
- new ConsoleMavenTransferListener(messageBuilderFactory, System.out, printResourceNames));
+ return new SimplexTransferListener(new ConsoleMavenTransferListener(System.out, printResourceNames));
}
protected TransferListener getBatchTransferListener() {
diff --git a/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java b/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java
index e678e62994..b070274c4b 100644
--- a/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java
+++ b/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java
@@ -19,10 +19,11 @@
package org.apache.maven.cli.transfer;
import java.io.PrintStream;
-import java.io.PrintWriter;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.util.Locale;
-import org.apache.maven.api.services.MessageBuilder;
-import org.apache.maven.api.services.MessageBuilderFactory;
+import org.apache.maven.jline.MessageUtils;
import org.eclipse.aether.transfer.AbstractTransferListener;
import org.eclipse.aether.transfer.TransferCancelledException;
import org.eclipse.aether.transfer.TransferEvent;
@@ -33,31 +34,177 @@ import org.eclipse.aether.transfer.TransferResource;
*/
@Deprecated
public abstract class AbstractMavenTransferListener extends AbstractTransferListener {
- public static final String STYLE = ".transfer:-faint";
- protected final MessageBuilderFactory messageBuilderFactory;
- protected final PrintWriter out;
+ private static final String ESC = "\u001B";
+ private static final String ANSI_DARK_SET = ESC + "[90m";
+ private static final String ANSI_DARK_RESET = ESC + "[0m";
- protected AbstractMavenTransferListener(MessageBuilderFactory messageBuilderFactory, PrintStream out) {
- this(messageBuilderFactory, new PrintWriter(out));
+ // CHECKSTYLE_OFF: LineLength
+ /**
+ * Formats file size with the associated SI prefix
+ * (GB, MB, kB) and using the patterns #0.0 for numbers between 1 and 10
+ * and ###0 for numbers between 10 and 1000+ by default.
+ *
+ * @see https://en.wikipedia.org/wiki/Metric_prefix
+ * @see https://en.wikipedia.org/wiki/Binary_prefix
+ * @see https://en.wikipedia.org/wiki/Octet_(computing)
+ */
+ // CHECKSTYLE_ON: LineLength
+ // TODO Move me to Maven Shared Utils
+ static class FileSizeFormat {
+ enum ScaleUnit {
+ BYTE {
+ @Override
+ public long bytes() {
+ return 1L;
+ }
+
+ @Override
+ public String symbol() {
+ return "B";
+ }
+ },
+ KILOBYTE {
+ @Override
+ public long bytes() {
+ return 1000L;
+ }
+
+ @Override
+ public String symbol() {
+ return "kB";
+ }
+ },
+ MEGABYTE {
+ @Override
+ public long bytes() {
+ return KILOBYTE.bytes() * KILOBYTE.bytes();
+ }
+
+ @Override
+ public String symbol() {
+ return "MB";
+ }
+ },
+ GIGABYTE {
+ @Override
+ public long bytes() {
+ return MEGABYTE.bytes() * KILOBYTE.bytes();
+ }
+ ;
+
+ @Override
+ public String symbol() {
+ return "GB";
+ }
+ };
+
+ public abstract long bytes();
+
+ public abstract String symbol();
+
+ public static ScaleUnit getScaleUnit(long size) {
+ if (size < 0L) {
+ throw new IllegalArgumentException("file size cannot be negative: " + size);
+ }
+
+ if (size >= GIGABYTE.bytes()) {
+ return GIGABYTE;
+ } else if (size >= MEGABYTE.bytes()) {
+ return MEGABYTE;
+ } else if (size >= KILOBYTE.bytes()) {
+ return KILOBYTE;
+ } else {
+ return BYTE;
+ }
+ }
+ }
+
+ private DecimalFormat smallFormat;
+ private DecimalFormat largeFormat;
+
+ FileSizeFormat(Locale locale) {
+ smallFormat = new DecimalFormat("#0.0", new DecimalFormatSymbols(locale));
+ largeFormat = new DecimalFormat("###0", new DecimalFormatSymbols(locale));
+ }
+
+ public String format(long size) {
+ return format(size, null);
+ }
+
+ public String format(long size, ScaleUnit unit) {
+ return format(size, unit, false);
+ }
+
+ public String format(long size, ScaleUnit unit, boolean omitSymbol) {
+ if (size < 0L) {
+ throw new IllegalArgumentException("file size cannot be negative: " + size);
+ }
+
+ if (unit == null) {
+ unit = ScaleUnit.getScaleUnit(size);
+ }
+
+ double scaledSize = (double) size / unit.bytes();
+ String scaledSymbol = " " + unit.symbol();
+
+ if (omitSymbol) {
+ scaledSymbol = "";
+ }
+
+ if (unit == ScaleUnit.BYTE) {
+ return largeFormat.format(size) + scaledSymbol;
+ }
+
+ if (scaledSize < 0.05 || scaledSize >= 10.0) {
+ return largeFormat.format(scaledSize) + scaledSymbol;
+ } else {
+ return smallFormat.format(scaledSize) + scaledSymbol;
+ }
+ }
+
+ public String formatProgress(long progressedSize, long size) {
+ if (progressedSize < 0L) {
+ throw new IllegalArgumentException("progressed file size cannot be negative: " + progressedSize);
+ }
+ if (size >= 0L && progressedSize > size) {
+ throw new IllegalArgumentException(
+ "progressed file size cannot be greater than size: " + progressedSize + " > " + size);
+ }
+
+ if (size >= 0L && progressedSize != size) {
+ ScaleUnit unit = ScaleUnit.getScaleUnit(size);
+ String formattedProgressedSize = format(progressedSize, unit, true);
+ String formattedSize = format(size, unit);
+
+ return formattedProgressedSize + "/" + formattedSize;
+ } else {
+ return format(progressedSize);
+ }
+ }
}
- protected AbstractMavenTransferListener(MessageBuilderFactory messageBuilderFactory, PrintWriter out) {
- this.messageBuilderFactory = messageBuilderFactory;
+ protected PrintStream out;
+
+ protected AbstractMavenTransferListener(PrintStream out) {
this.out = out;
}
@Override
public void transferInitiated(TransferEvent event) {
+ String darkOn = MessageUtils.isColorEnabled() ? ANSI_DARK_SET : "";
+ String darkOff = MessageUtils.isColorEnabled() ? ANSI_DARK_RESET : "";
+
String action = event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploading" : "Downloading";
String direction = event.getRequestType() == TransferEvent.RequestType.PUT ? "to" : "from";
TransferResource resource = event.getResource();
- MessageBuilder message = messageBuilderFactory.builder();
- message.style(STYLE).append(action).append(' ').append(direction).append(' ');
- message.resetStyle().append(resource.getRepositoryId());
- message.style(STYLE).append(": ").append(resource.getRepositoryUrl());
- message.resetStyle().append(resource.getResourceName());
+ StringBuilder message = new StringBuilder();
+ message.append(darkOn).append(action).append(' ').append(direction).append(' ');
+ message.append(darkOff).append(resource.getRepositoryId());
+ message.append(darkOn).append(": ").append(resource.getRepositoryUrl());
+ message.append(darkOff).append(resource.getResourceName());
out.println(message.toString());
}
@@ -72,29 +219,30 @@ public abstract class AbstractMavenTransferListener extends AbstractTransferList
@Override
public void transferSucceeded(TransferEvent event) {
+ String darkOn = MessageUtils.isColorEnabled() ? ANSI_DARK_SET : "";
+ String darkOff = MessageUtils.isColorEnabled() ? ANSI_DARK_RESET : "";
+
String action = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
String direction = event.getRequestType() == TransferEvent.RequestType.PUT ? "to" : "from";
TransferResource resource = event.getResource();
long contentLength = event.getTransferredBytes();
- FileSizeFormat format = new FileSizeFormat();
+ FileSizeFormat format = new FileSizeFormat(Locale.ENGLISH);
- MessageBuilder message = messageBuilderFactory.builder();
- message.append(action).style(STYLE).append(' ').append(direction).append(' ');
- message.resetStyle().append(resource.getRepositoryId());
- message.style(STYLE).append(": ").append(resource.getRepositoryUrl());
- message.resetStyle().append(resource.getResourceName());
- message.style(STYLE).append(" (").append(format.format(contentLength));
+ StringBuilder message = new StringBuilder();
+ message.append(action).append(darkOn).append(' ').append(direction).append(' ');
+ message.append(darkOff).append(resource.getRepositoryId());
+ message.append(darkOn).append(": ").append(resource.getRepositoryUrl());
+ message.append(darkOff).append(resource.getResourceName());
+ message.append(darkOn).append(" (").append(format.format(contentLength));
long duration = System.currentTimeMillis() - resource.getTransferStartTime();
if (duration > 0L) {
double bytesPerSecond = contentLength / (duration / 1000.0);
- message.append(" at ");
- format.format(message, (long) bytesPerSecond);
- message.append("/s");
+ message.append(" at ").append(format.format((long) bytesPerSecond)).append("/s");
}
- message.append(')').resetStyle();
+ message.append(')').append(darkOff);
out.println(message.toString());
}
}
diff --git a/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/BatchModeMavenTransferListener.java b/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/BatchModeMavenTransferListener.java
new file mode 100644
index 0000000000..2e13e5b134
--- /dev/null
+++ b/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/BatchModeMavenTransferListener.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.cli.transfer;
+
+import java.io.PrintStream;
+
+/**
+ * BatchModeMavenTransferListener
+ */
+@Deprecated
+public class BatchModeMavenTransferListener extends AbstractMavenTransferListener {
+ public BatchModeMavenTransferListener(PrintStream out) {
+ super(out);
+ }
+}
diff --git a/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java b/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java
index c03d001491..9146d6b720 100644
--- a/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java
+++ b/compat/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java
@@ -19,12 +19,12 @@
package org.apache.maven.cli.transfer;
import java.io.PrintStream;
-import java.io.PrintWriter;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.Locale;
import java.util.Map;
-import org.apache.maven.api.services.MessageBuilderFactory;
import org.eclipse.aether.transfer.TransferCancelledException;
import org.eclipse.aether.transfer.TransferEvent;
import org.eclipse.aether.transfer.TransferResource;
@@ -37,21 +37,14 @@ import org.eclipse.aether.transfer.TransferResource;
@Deprecated
public class ConsoleMavenTransferListener extends AbstractMavenTransferListener {
- private final Map transfers = new LinkedHashMap<>();
- private final FileSizeFormat format = new FileSizeFormat(); // use in a synchronized fashion
- private final StringBuilder buffer = new StringBuilder(128); // use in a synchronized fashion
+ private final Map transfers =
+ Collections.synchronizedMap(new LinkedHashMap());
private final boolean printResourceNames;
private int lastLength;
- public ConsoleMavenTransferListener(
- MessageBuilderFactory messageBuilderFactory, PrintStream out, boolean printResourceNames) {
- this(messageBuilderFactory, new PrintWriter(out), printResourceNames);
- }
-
- public ConsoleMavenTransferListener(
- MessageBuilderFactory messageBuilderFactory, PrintWriter out, boolean printResourceNames) {
- super(messageBuilderFactory, out);
+ public ConsoleMavenTransferListener(PrintStream out, boolean printResourceNames) {
+ super(out);
this.printResourceNames = printResourceNames;
}
@@ -76,36 +69,19 @@ public class ConsoleMavenTransferListener extends AbstractMavenTransferListener
new TransferResourceIdentifier(resource),
new TransferResourceAndSize(resource, event.getTransferredBytes()));
+ StringBuilder buffer = new StringBuilder(128);
buffer.append("Progress (").append(transfers.size()).append("): ");
- Iterator entries = transfers.values().iterator();
- while (entries.hasNext()) {
- TransferResourceAndSize entry = entries.next();
- // just in case, make sure 0 <= complete <= total
- long complete = Math.max(0, entry.transferredBytes);
- long total = Math.max(complete, entry.resource.getContentLength());
-
- String resourceName = entry.resource.getResourceName();
-
- if (printResourceNames) {
- int idx = resourceName.lastIndexOf('/');
-
- if (idx < 0) {
- buffer.append(resourceName);
- } else {
- buffer.append(resourceName, idx + 1, resourceName.length());
+ synchronized (transfers) {
+ Iterator entries = transfers.values().iterator();
+ while (entries.hasNext()) {
+ TransferResourceAndSize entry = entries.next();
+ long total = entry.resource.getContentLength();
+ Long complete = entry.transferredBytes;
+ buffer.append(getStatus(entry.resource.getResourceName(), complete, total));
+ if (entries.hasNext()) {
+ buffer.append(" | ");
}
- buffer.append(" (");
- }
-
- format.formatProgress(buffer, complete, total);
-
- if (printResourceNames) {
- buffer.append(")");
- }
-
- if (entries.hasNext()) {
- buffer.append(" | ");
}
}
@@ -115,7 +91,35 @@ public class ConsoleMavenTransferListener extends AbstractMavenTransferListener
buffer.append('\r');
out.print(buffer);
out.flush();
- buffer.setLength(0);
+ }
+
+ private String getStatus(String resourceName, long complete, long total) {
+ FileSizeFormat format = new FileSizeFormat(Locale.ENGLISH);
+ StringBuilder status = new StringBuilder();
+
+ if (printResourceNames) {
+ status.append(resourceName(resourceName));
+ status.append(" (");
+ }
+
+ status.append(format.formatProgress(complete, total));
+
+ if (printResourceNames) {
+ status.append(")");
+ }
+
+ return status.toString();
+ }
+
+ private String resourceName(String resourceName) {
+ if (resourceName == null || resourceName.trim().isEmpty()) {
+ return "";
+ }
+ final int pos = resourceName.lastIndexOf("/");
+ if (pos == -1 || pos == resourceName.length() - 1) {
+ return "";
+ }
+ return resourceName.substring(pos + 1);
}
private void pad(StringBuilder buffer, int spaces) {
@@ -145,14 +149,23 @@ public class ConsoleMavenTransferListener extends AbstractMavenTransferListener
private void overridePreviousTransfer(TransferEvent event) {
if (lastLength > 0) {
+ StringBuilder buffer = new StringBuilder(128);
pad(buffer, lastLength);
buffer.append('\r');
out.print(buffer);
out.flush();
lastLength = 0;
- buffer.setLength(0);
}
}
- private record TransferResourceAndSize(TransferResource resource, long transferredBytes) {}
+ private final class TransferResourceAndSize {
+
+ private final TransferResource resource;
+ private final long transferredBytes;
+
+ private TransferResourceAndSize(TransferResource resource, long transferredBytes) {
+ this.resource = resource;
+ this.transferredBytes = transferredBytes;
+ }
+ }
}
diff --git a/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListenerTest.java b/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListenerTest.java
deleted file mode 100644
index 8a7f4426f5..0000000000
--- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListenerTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.cli.transfer;
-
-import java.io.File;
-import java.io.PrintWriter;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.maven.jline.JLineMessageBuilderFactory;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.transfer.TransferCancelledException;
-import org.eclipse.aether.transfer.TransferEvent;
-import org.eclipse.aether.transfer.TransferListener;
-import org.eclipse.aether.transfer.TransferResource;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-@Deprecated
-class ConsoleMavenTransferListenerTest {
-
- private CountDownLatch startLatch;
- private CountDownLatch endLatch;
-
- @Test
- void testTransferProgressedWithPrintResourceNames() throws Exception {
- int size = 1000;
- ExecutorService service = Executors.newFixedThreadPool(size * 2);
- startLatch = new CountDownLatch(size);
- endLatch = new CountDownLatch(size);
- Map output = new ConcurrentHashMap();
-
- TransferListener listener = new SimplexTransferListener(new ConsoleMavenTransferListener(
- new JLineMessageBuilderFactory(),
- new PrintWriter(System.out) {
-
- @Override
- public void print(Object o) {
-
- String string = o.toString();
- int i = string.length() - 1;
- while (i >= 0) {
- char c = string.charAt(i);
- if (c == '\n' || c == '\r' || c == ' ') i--;
- else break;
- }
-
- string = string.substring(0, i + 1).trim();
- output.put(string, string);
- System.out.print(o);
- }
- },
- true));
- TransferResource resource =
- new TransferResource(null, null, "http://maven.org/test/test-resource", new File(""), null);
- resource.setContentLength(size - 1);
-
- DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(h -> false); // no close handle
-
- // warm up
- test(listener, session, resource, 0);
-
- for (int i = 1; i < size; i++) {
- final int bytes = i;
-
- service.execute(() -> {
- test(listener, session, resource, bytes);
- });
- }
-
- // start all threads at once
- try {
- startLatch.await();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- // wait for all thread to end
- try {
- endLatch.await();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- // despite all are back, we need to make sure all the events are processed (are async)
- // this one should block until all processed
- listener.transferSucceeded(new TransferEvent.Builder(session, resource)
- .setType(TransferEvent.EventType.SUCCEEDED)
- .build());
-
- StringBuilder message = new StringBuilder("Messages [");
- boolean test = true;
- for (int i = 0; i < 999; i++) {
- boolean ok = output.containsKey("Progress (1): test-resource (" + i + "/999 B)");
- if (!ok) {
- System.out.println("false : " + i);
- message.append(i + ",");
- }
- test = test & ok;
- }
- assertTrue(test, message + "] are missing in " + output);
- }
-
- private void test(
- TransferListener listener,
- DefaultRepositorySystemSession session,
- TransferResource resource,
- final int bytes) {
- TransferEvent event = new TransferEvent.Builder(session, resource)
- .setType(TransferEvent.EventType.PROGRESSED)
- .setTransferredBytes(bytes)
- .build();
- startLatch.countDown();
- try {
- listener.transferProgressed(event);
- } catch (TransferCancelledException e) {
- }
- endLatch.countDown();
- }
-}
diff --git a/compat/maven-model-builder/pom.xml b/compat/maven-model-builder/pom.xml
index 31b91726bc..1731dbda56 100644
--- a/compat/maven-model-builder/pom.xml
+++ b/compat/maven-model-builder/pom.xml
@@ -67,6 +67,10 @@ under the License.
org.apache.mavenmaven-model
+
+ org.apache.maven
+ maven-artifact
+ org.apache.mavenmaven-builder-support
@@ -93,6 +97,10 @@ under the License.
org.eclipse.sisu.injectprovided
+
+ org.codehaus.plexus
+ plexus-utils
+
@@ -115,11 +123,6 @@ under the License.
xmlunit-matcherstest
-
- org.codehaus.plexus
- plexus-utils
- test
-
@@ -141,52 +144,50 @@ under the License.
- org.apache.maven.model.building.DefaultModelBuilder#DefaultModelBuilder():CONSTRUCTOR_REMOVED
- org.apache.maven.model.building.DefaultModelProcessor#setModelLocator(org.apache.maven.model.locator.ModelLocator):METHOD_REMOVED
- org.apache.maven.model.building.DefaultModelProcessor#setModelReader(org.apache.maven.model.io.ModelReader):METHOD_REMOVED
- org.apache.maven.model.building.DefaultModelProcessor#DefaultModelProcessor():CONSTRUCTOR_REMOVED
- org.apache.maven.model.building.ModelCache#get(java.lang.String,java.lang.String,java.lang.String,java.lang.String):METHOD_REMOVED
- org.apache.maven.model.building.ModelCache#put(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Object):METHOD_REMOVED
- org.apache.maven.model.composition.DependencyManagementImporter#importManagement(org.apache.maven.model.Model,java.util.List,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_REMOVED
- org.apache.maven.model.composition.DefaultDependencyManagementImporter#importManagement(org.apache.maven.model.Model,java.util.List,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_REMOVED
- org.apache.maven.model.inheritance.DefaultInheritanceAssembler
- org.apache.maven.model.inheritance.InheritanceAssembler#assembleModelInheritance(org.apache.maven.model.Model,org.apache.maven.model.Model,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_REMOVED
- org.apache.maven.model.interpolation.AbstractStringBasedModelInterpolator
- org.apache.maven.model.interpolation.StringSearchModelInterpolator
- org.apache.maven.model.interpolation.StringVisitorModelInterpolator
- org.apache.maven.model.io.DefaultModelReader#DefaultModelReader():CONSTRUCTOR_REMOVED
- org.apache.maven.model.locator.ModelLocator#locateExistingPom(java.io.File):METHOD_NEW_DEFAULT
- org.apache.maven.model.management.DefaultDependencyManagementInjector$ManagementModelMerger
- org.apache.maven.model.management.DefaultPluginManagementInjector$ManagementModelMerger
- org.apache.maven.model.merge.MavenModelMerger
- org.apache.maven.model.normalization.DefaultModelNormalizer$DuplicateMerger#mergePlugin(org.apache.maven.model.Plugin,org.apache.maven.model.Plugin):METHOD_REMOVED
- org.apache.maven.model.normalization.DefaultModelNormalizer$DuplicateMerger:METHOD_REMOVED_IN_SUPERCLASS
- org.apache.maven.model.path.DefaultModelPathTranslator#setPathTranslator(org.apache.maven.model.path.PathTranslator):METHOD_REMOVED
- org.apache.maven.model.path.DefaultModelPathTranslator#DefaultModelPathTranslator():CONSTRUCTOR_REMOVED
- org.apache.maven.model.path.DefaultModelUrlNormalizer#setUrlNormalizer(org.apache.maven.model.path.UrlNormalizer):METHOD_REMOVED
- org.apache.maven.model.path.DefaultModelUrlNormalizer#DefaultModelUrlNormalizer():CONSTRUCTOR_REMOVED
- org.apache.maven.model.path.ProfileActivationFilePathInterpolator#setPathTranslator(org.apache.maven.model.path.PathTranslator):METHOD_REMOVED
- org.apache.maven.model.path.ProfileActivationFilePathInterpolator#ProfileActivationFilePathInterpolator():CONSTRUCTOR_REMOVED
- org.apache.maven.model.profile.activation.FileProfileActivator#setProfileActivationFilePathInterpolator(org.apache.maven.model.path.ProfileActivationFilePathInterpolator):METHOD_REMOVED
- org.apache.maven.model.profile.activation.FileProfileActivator#FileProfileActivator():CONSTRUCTOR_REMOVED
- org.apache.maven.model.profile.DefaultProfileInjector
- org.apache.maven.model.profile.ProfileInjector#injectProfile(org.apache.maven.api.model.Model,org.apache.maven.api.model.Profile,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_NEW_DEFAULT
- org.apache.maven.model.profile.ProfileInjector#injectProfiles(org.apache.maven.api.model.Model,java.util.List,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_NEW_DEFAULT
- org.apache.maven.model.profile.ProfileSelector#getActiveProfilesV4(java.util.Collection,org.apache.maven.model.profile.ProfileActivationContext,org.apache.maven.model.building.ModelProblemCollector):METHOD_NEW_DEFAULT
- org.apache.maven.model.resolution.InvalidRepositoryException#getRepository():METHOD_RETURN_TYPE_CHANGED
- org.apache.maven.model.resolution.InvalidRepositoryException#InvalidRepositoryException(java.lang.String,org.apache.maven.model.Repository,java.lang.Throwable):CONSTRUCTOR_REMOVED
- org.apache.maven.model.resolution.InvalidRepositoryException#InvalidRepositoryException(java.lang.String,org.apache.maven.model.Repository):CONSTRUCTOR_REMOVED
- org.apache.maven.model.resolution.ModelResolver#addRepository(org.apache.maven.api.model.Repository):METHOD_NEW_DEFAULT
- org.apache.maven.model.resolution.ModelResolver#addRepository(org.apache.maven.api.model.Repository,boolean):METHOD_NEW_DEFAULT
- org.apache.maven.model.resolution.ModelResolver#resolveModel(org.apache.maven.api.model.Parent,java.util.concurrent.atomic.AtomicReference):METHOD_NEW_DEFAULT
- org.apache.maven.model.resolution.ModelResolver#resolveModel(org.apache.maven.api.model.Dependency,java.util.concurrent.atomic.AtomicReference):METHOD_NEW_DEFAULT
- org.apache.maven.model.superpom.DefaultSuperPomProvider#getSuperModel(java.lang.String):METHOD_RETURN_TYPE_CHANGED
- org.apache.maven.model.superpom.DefaultSuperPomProvider#setModelProcessor(org.apache.maven.model.building.ModelProcessor):METHOD_REMOVED
- org.apache.maven.model.superpom.DefaultSuperPomProvider#DefaultSuperPomProvider():CONSTRUCTOR_REMOVED
- org.apache.maven.model.superpom.SuperPomProvider#getSuperModel(java.lang.String):METHOD_RETURN_TYPE_CHANGED
- org.apache.maven.model.validation.DefaultModelValidator#validateDependencyVersion(org.apache.maven.model.building.ModelProblemCollector,org.apache.maven.model.Dependency,java.lang.String):METHOD_REMOVED
- org.apache.maven.model.validation.ModelValidator#validateFileModel(org.apache.maven.model.Model,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_NEW_DEFAULT
- org.apache.maven.model.validation.ModelValidator#validateExternalProfiles(java.util.List,org.apache.maven.model.Model,org.apache.maven.model.building.ModelBuildingRequest,org.apache.maven.model.building.ModelProblemCollector):METHOD_NEW_DEFAULT
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/BuildModelSourceTransformer.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/BuildModelSourceTransformer.java
deleted file mode 100644
index f0c01c81c6..0000000000
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/BuildModelSourceTransformer.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.model.building;
-
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.Objects;
-import java.util.Optional;
-
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.Model;
-import org.apache.maven.model.Parent;
-
-/**
- * ModelSourceTransformer for the build pom
- *
- * @since 4.0.0
- * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
- */
-@Named
-@Singleton
-@Deprecated(since = "4.0.0")
-class BuildModelSourceTransformer implements ModelSourceTransformer {
-
- public static final String NAMESPACE_PREFIX = "http://maven.apache.org/POM/";
-
- @Override
- public void transform(Path pomFile, TransformerContext context, Model model) {
- handleModelVersion(model);
- handleParent(pomFile, context, model);
- handleReactorDependencies(context, model);
- handleCiFriendlyVersion(context, model);
- }
-
- //
- // Infer modelVersion from namespace URI
- //
- void handleModelVersion(Model model) {
- String namespace = model.getDelegate().getNamespaceUri();
- if (model.getModelVersion() == null && namespace != null && namespace.startsWith(NAMESPACE_PREFIX)) {
- model.setModelVersion(namespace.substring(NAMESPACE_PREFIX.length()));
- }
- }
-
- //
- // Infer parent information
- //
- void handleParent(Path pomFile, TransformerContext context, Model model) {
- Parent parent = model.getParent();
- if (parent != null) {
- String version = parent.getVersion();
- String path = Optional.ofNullable(parent.getRelativePath()).orElse("..");
- if (version == null && !path.isEmpty()) {
- Optional resolvedParent = resolveRelativePath(
- pomFile, context, Paths.get(path), parent.getGroupId(), parent.getArtifactId());
- resolvedParent.ifPresent(relativeProject -> parent.setVersion(relativeProject.getVersion()));
- }
- }
- }
-
- //
- // CI friendly versions
- //
- void handleCiFriendlyVersion(TransformerContext context, Model model) {
- String version = model.getVersion();
- String modVersion = replaceCiFriendlyVersion(context, version);
- model.setVersion(modVersion);
-
- Parent parent = model.getParent();
- if (parent != null) {
- version = parent.getVersion();
- modVersion = replaceCiFriendlyVersion(context, version);
- parent.setVersion(modVersion);
- }
- }
-
- //
- // Infer inner reactor dependencies version
- //
- void handleReactorDependencies(TransformerContext context, Model model) {
- for (Dependency dep : model.getDependencies()) {
- if (dep.getVersion() == null) {
- Model depModel =
- context.getRawModel(model.getDelegate().getPomFile(), dep.getGroupId(), dep.getArtifactId());
- if (depModel != null) {
- String v = depModel.getVersion();
- if (v == null && depModel.getParent() != null) {
- v = depModel.getParent().getVersion();
- }
- dep.setVersion(v);
- }
- }
- }
- }
-
- protected String replaceCiFriendlyVersion(TransformerContext context, String version) {
- if (version != null) {
- for (String key : Arrays.asList("changelist", "revision", "sha1")) {
- String val = context.getUserProperty(key);
- if (val != null) {
- version = version.replace("${" + key + "}", val);
- }
- }
- }
- return version;
- }
-
- protected Optional resolveRelativePath(
- Path pomFile, TransformerContext context, Path relativePath, String groupId, String artifactId) {
- Path pomPath = pomFile.resolveSibling(relativePath).normalize();
- if (Files.isDirectory(pomPath)) {
- pomPath = context.locate(pomPath);
- }
-
- if (pomPath == null || !Files.isRegularFile(pomPath)) {
- return Optional.empty();
- }
-
- Optional mappedProject = Optional.ofNullable(context.getRawModel(pomFile, pomPath.normalize()))
- .map(BuildModelSourceTransformer::toRelativeProject);
-
- if (mappedProject.isPresent()) {
- RelativeProject project = mappedProject.get();
-
- if (Objects.equals(groupId, project.getGroupId()) && Objects.equals(artifactId, project.getArtifactId())) {
- return mappedProject;
- }
- }
- return Optional.empty();
- }
-
- private static RelativeProject toRelativeProject(final org.apache.maven.model.Model m) {
- String groupId = m.getGroupId();
- if (groupId == null && m.getParent() != null) {
- groupId = m.getParent().getGroupId();
- }
-
- String version = m.getVersion();
- if (version == null && m.getParent() != null) {
- version = m.getParent().getVersion();
- }
-
- return new RelativeProject(groupId, m.getArtifactId(), version);
- }
-
- static class RelativeProject {
- private final String groupId;
-
- private final String artifactId;
-
- private final String version;
-
- RelativeProject(String groupId, String artifactId, String version) {
- this.groupId = groupId;
- this.artifactId = artifactId;
- this.version = version;
- }
-
- public String getGroupId() {
- return groupId;
- }
-
- public String getArtifactId() {
- return artifactId;
- }
-
- public String getVersion() {
- return version;
- }
- }
-}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
index 8dd4de675c..4bb75270a4 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java
@@ -24,10 +24,9 @@ import javax.inject.Singleton;
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.Field;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
@@ -36,37 +35,31 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.function.Supplier;
-import java.util.function.UnaryOperator;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
+import java.util.function.Consumer;
+import java.util.stream.IntStream;
-import org.apache.maven.api.VersionRange;
-import org.apache.maven.api.model.ActivationFile;
-import org.apache.maven.api.model.Exclusion;
-import org.apache.maven.api.model.InputSource;
-import org.apache.maven.api.services.VersionParserException;
-import org.apache.maven.api.services.model.ModelVersionParser;
-import org.apache.maven.building.Source;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Activation;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.InputLocation;
+import org.apache.maven.model.InputLocationTracker;
+import org.apache.maven.model.InputSource;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Profile;
+import org.apache.maven.model.Repository;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.composition.DependencyManagementImporter;
import org.apache.maven.model.inheritance.InheritanceAssembler;
import org.apache.maven.model.interpolation.ModelInterpolator;
-import org.apache.maven.model.interpolation.ModelVersionProcessor;
import org.apache.maven.model.io.ModelParseException;
-import org.apache.maven.model.io.ModelReader;
import org.apache.maven.model.management.DependencyManagementInjector;
import org.apache.maven.model.management.PluginManagementInjector;
import org.apache.maven.model.normalization.ModelNormalizer;
@@ -86,609 +79,178 @@ import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.apache.maven.model.resolution.WorkspaceModelResolver;
import org.apache.maven.model.superpom.SuperPomProvider;
-import org.apache.maven.model.v4.MavenTransformer;
-import org.apache.maven.model.validation.DefaultModelValidator;
import org.apache.maven.model.validation.ModelValidator;
import org.codehaus.plexus.interpolation.InterpolationException;
-import org.codehaus.plexus.interpolation.Interpolator;
import org.codehaus.plexus.interpolation.MapBasedValueSource;
import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
import org.codehaus.plexus.interpolation.StringSearchInterpolator;
+import org.codehaus.plexus.util.StringUtils;
import org.eclipse.sisu.Nullable;
-import static org.apache.maven.api.services.ModelBuilder.MODEL_VERSION_4_0_0;
import static org.apache.maven.model.building.Result.error;
import static org.apache.maven.model.building.Result.newResult;
/**
* @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
*/
+@SuppressWarnings("UnusedReturnValue")
@Named
@Singleton
@Deprecated(since = "4.0.0")
public class DefaultModelBuilder implements ModelBuilder {
-
- private final ModelProcessor modelProcessor;
- private final ModelValidator modelValidator;
- private final ModelNormalizer modelNormalizer;
- private final ModelInterpolator modelInterpolator;
- private final ModelPathTranslator modelPathTranslator;
- private final ModelUrlNormalizer modelUrlNormalizer;
- private final SuperPomProvider superPomProvider;
- private final InheritanceAssembler inheritanceAssembler;
- private final ProfileSelector profileSelector;
- private final ProfileInjector profileInjector;
- private final PluginManagementInjector pluginManagementInjector;
- private final DependencyManagementInjector dependencyManagementInjector;
- private final DependencyManagementImporter dependencyManagementImporter;
- private final LifecycleBindingsInjector lifecycleBindingsInjector;
- private final PluginConfigurationExpander pluginConfigurationExpander;
- private final ReportConfigurationExpander reportConfigurationExpander;
- private final ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator;
- private final ModelVersionProcessor versionProcessor;
- private final ModelSourceTransformer transformer;
- private final ModelVersionParser versionParser;
-
- @SuppressWarnings("checkstyle:ParameterNumber")
@Inject
- public DefaultModelBuilder(
- ModelProcessor modelProcessor,
- ModelValidator modelValidator,
- ModelNormalizer modelNormalizer,
- ModelInterpolator modelInterpolator,
- ModelPathTranslator modelPathTranslator,
- ModelUrlNormalizer modelUrlNormalizer,
- SuperPomProvider superPomProvider,
- InheritanceAssembler inheritanceAssembler,
- ProfileSelector profileSelector,
- ProfileInjector profileInjector,
- PluginManagementInjector pluginManagementInjector,
- DependencyManagementInjector dependencyManagementInjector,
- DependencyManagementImporter dependencyManagementImporter,
- @Nullable LifecycleBindingsInjector lifecycleBindingsInjector,
- PluginConfigurationExpander pluginConfigurationExpander,
- ReportConfigurationExpander reportConfigurationExpander,
- ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator,
- ModelVersionProcessor versionProcessor,
- ModelSourceTransformer transformer,
- ModelVersionParser versionParser) {
- this.modelProcessor = modelProcessor;
- this.modelValidator = modelValidator;
- this.modelNormalizer = modelNormalizer;
- this.modelInterpolator = modelInterpolator;
- this.modelPathTranslator = modelPathTranslator;
- this.modelUrlNormalizer = modelUrlNormalizer;
- this.superPomProvider = superPomProvider;
- this.inheritanceAssembler = inheritanceAssembler;
- this.profileSelector = profileSelector;
- this.profileInjector = profileInjector;
- this.pluginManagementInjector = pluginManagementInjector;
- this.dependencyManagementInjector = dependencyManagementInjector;
- this.dependencyManagementImporter = dependencyManagementImporter;
- this.lifecycleBindingsInjector = lifecycleBindingsInjector;
- this.pluginConfigurationExpander = pluginConfigurationExpander;
- this.reportConfigurationExpander = reportConfigurationExpander;
- this.profileActivationFilePathInterpolator = profileActivationFilePathInterpolator;
- this.versionProcessor = versionProcessor;
- this.transformer = transformer;
- this.versionParser = versionParser;
- }
+ private ModelProcessor modelProcessor;
+
+ @Inject
+ private ModelValidator modelValidator;
+
+ @Inject
+ private ModelNormalizer modelNormalizer;
+
+ @Inject
+ private ModelInterpolator modelInterpolator;
+
+ @Inject
+ private ModelPathTranslator modelPathTranslator;
+
+ @Inject
+ private ModelUrlNormalizer modelUrlNormalizer;
+
+ @Inject
+ private SuperPomProvider superPomProvider;
+
+ @Inject
+ private InheritanceAssembler inheritanceAssembler;
+
+ @Inject
+ private ProfileSelector profileSelector;
+
+ @Inject
+ private ProfileInjector profileInjector;
+
+ @Inject
+ private PluginManagementInjector pluginManagementInjector;
+
+ @Inject
+ private DependencyManagementInjector dependencyManagementInjector;
+
+ @Inject
+ private DependencyManagementImporter dependencyManagementImporter;
+
+ @Inject
+ @Nullable
+ private LifecycleBindingsInjector lifecycleBindingsInjector;
+
+ @Inject
+ private PluginConfigurationExpander pluginConfigurationExpander;
+
+ @Inject
+ private ReportConfigurationExpander reportConfigurationExpander;
+
+ @Inject
+ private ReportingConverter reportingConverter;
+
+ @Inject
+ private ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator;
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setModelProcessor(ModelProcessor)
- */
- @Deprecated
public DefaultModelBuilder setModelProcessor(ModelProcessor modelProcessor) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setModelProcessor(ModelProcessor)
- */
- @Deprecated
- public DefaultModelBuilder setModelValidator(ModelValidator modelValidator) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setModelNormalizer(ModelNormalizer)
- */
- @Deprecated
- public DefaultModelBuilder setModelNormalizer(ModelNormalizer modelNormalizer) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setModelInterpolator(ModelInterpolator)
- */
- @Deprecated
- public DefaultModelBuilder setModelInterpolator(ModelInterpolator modelInterpolator) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setModelPathTranslator(ModelPathTranslator)
- */
- @Deprecated
- public DefaultModelBuilder setModelPathTranslator(ModelPathTranslator modelPathTranslator) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setModelUrlNormalizer(ModelUrlNormalizer)
- */
- @Deprecated
- public DefaultModelBuilder setModelUrlNormalizer(ModelUrlNormalizer modelUrlNormalizer) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setSuperPomProvider(SuperPomProvider)
- */
- @Deprecated
- public DefaultModelBuilder setSuperPomProvider(SuperPomProvider superPomProvider) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setInheritanceAssembler(InheritanceAssembler)
- */
- @Deprecated
- public DefaultModelBuilder setInheritanceAssembler(InheritanceAssembler inheritanceAssembler) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setProfileSelector(ProfileSelector)
- */
- @Deprecated
- public DefaultModelBuilder setProfileSelector(ProfileSelector profileSelector) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setProfileInjector(ProfileInjector)
- */
- @Deprecated
- public DefaultModelBuilder setProfileInjector(ProfileInjector profileInjector) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setPluginManagementInjector(PluginManagementInjector)
- */
- @Deprecated
- public DefaultModelBuilder setPluginManagementInjector(PluginManagementInjector pluginManagementInjector) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setDependencyManagementInjector(DependencyManagementInjector)
- */
- @Deprecated
- public DefaultModelBuilder setDependencyManagementInjector(
- DependencyManagementInjector dependencyManagementInjector) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setDependencyManagementImporter(DependencyManagementImporter)
- */
- @Deprecated
- public DefaultModelBuilder setDependencyManagementImporter(
- DependencyManagementImporter dependencyManagementImporter) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setLifecycleBindingsInjector(LifecycleBindingsInjector)
- */
- @Deprecated
- public DefaultModelBuilder setLifecycleBindingsInjector(LifecycleBindingsInjector lifecycleBindingsInjector) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setPluginConfigurationExpander(PluginConfigurationExpander)
- */
- @Deprecated
- public DefaultModelBuilder setPluginConfigurationExpander(PluginConfigurationExpander pluginConfigurationExpander) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setReportConfigurationExpander(ReportConfigurationExpander)
- */
- @Deprecated
- public DefaultModelBuilder setReportConfigurationExpander(ReportConfigurationExpander reportConfigurationExpander) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setProfileActivationFilePathInterpolator(ProfileActivationFilePathInterpolator)
- */
- @Deprecated
- public DefaultModelBuilder setProfileActivationFilePathInterpolator(
- ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator) {
- return new DefaultModelBuilder(
- modelProcessor,
- modelValidator,
- modelNormalizer,
- modelInterpolator,
- modelPathTranslator,
- modelUrlNormalizer,
- superPomProvider,
- inheritanceAssembler,
- profileSelector,
- profileInjector,
- pluginManagementInjector,
- dependencyManagementInjector,
- dependencyManagementImporter,
- lifecycleBindingsInjector,
- pluginConfigurationExpander,
- reportConfigurationExpander,
- profileActivationFilePathInterpolator,
- versionProcessor,
- transformer,
- versionParser);
- }
-
- /**
- * @deprecated since Maven 4
- * @see DefaultModelBuilderFactory#setReportingConverter(ReportingConverter)
- */
- @Deprecated
- public DefaultModelBuilder setReportingConverter(ReportingConverter reportingConverter) {
+ this.modelProcessor = modelProcessor;
return this;
}
- @Override
- public DefaultTransformerContextBuilder newTransformerContextBuilder() {
- return new DefaultTransformerContextBuilder(this);
+ public DefaultModelBuilder setModelValidator(ModelValidator modelValidator) {
+ this.modelValidator = modelValidator;
+ return this;
}
+ public DefaultModelBuilder setModelNormalizer(ModelNormalizer modelNormalizer) {
+ this.modelNormalizer = modelNormalizer;
+ return this;
+ }
+
+ public DefaultModelBuilder setModelInterpolator(ModelInterpolator modelInterpolator) {
+ this.modelInterpolator = modelInterpolator;
+ return this;
+ }
+
+ public DefaultModelBuilder setModelPathTranslator(ModelPathTranslator modelPathTranslator) {
+ this.modelPathTranslator = modelPathTranslator;
+ return this;
+ }
+
+ public DefaultModelBuilder setModelUrlNormalizer(ModelUrlNormalizer modelUrlNormalizer) {
+ this.modelUrlNormalizer = modelUrlNormalizer;
+ return this;
+ }
+
+ public DefaultModelBuilder setSuperPomProvider(SuperPomProvider superPomProvider) {
+ this.superPomProvider = superPomProvider;
+ return this;
+ }
+
+ public DefaultModelBuilder setProfileSelector(ProfileSelector profileSelector) {
+ this.profileSelector = profileSelector;
+ return this;
+ }
+
+ public DefaultModelBuilder setProfileInjector(ProfileInjector profileInjector) {
+ this.profileInjector = profileInjector;
+ return this;
+ }
+
+ public DefaultModelBuilder setInheritanceAssembler(InheritanceAssembler inheritanceAssembler) {
+ this.inheritanceAssembler = inheritanceAssembler;
+ return this;
+ }
+
+ public DefaultModelBuilder setDependencyManagementImporter(DependencyManagementImporter depMgmtImporter) {
+ this.dependencyManagementImporter = depMgmtImporter;
+ return this;
+ }
+
+ public DefaultModelBuilder setDependencyManagementInjector(DependencyManagementInjector depMgmtInjector) {
+ this.dependencyManagementInjector = depMgmtInjector;
+ return this;
+ }
+
+ public DefaultModelBuilder setLifecycleBindingsInjector(LifecycleBindingsInjector lifecycleBindingsInjector) {
+ this.lifecycleBindingsInjector = lifecycleBindingsInjector;
+ return this;
+ }
+
+ public DefaultModelBuilder setPluginConfigurationExpander(PluginConfigurationExpander pluginConfigurationExpander) {
+ this.pluginConfigurationExpander = pluginConfigurationExpander;
+ return this;
+ }
+
+ public DefaultModelBuilder setPluginManagementInjector(PluginManagementInjector pluginManagementInjector) {
+ this.pluginManagementInjector = pluginManagementInjector;
+ return this;
+ }
+
+ public DefaultModelBuilder setReportConfigurationExpander(ReportConfigurationExpander reportConfigurationExpander) {
+ this.reportConfigurationExpander = reportConfigurationExpander;
+ return this;
+ }
+
+ public DefaultModelBuilder setReportingConverter(ReportingConverter reportingConverter) {
+ this.reportingConverter = reportingConverter;
+ return this;
+ }
+
+ public DefaultModelBuilder setProfileActivationFilePathInterpolator(
+ ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator) {
+ this.profileActivationFilePathInterpolator = profileActivationFilePathInterpolator;
+ return this;
+ }
+
+ @SuppressWarnings("checkstyle:methodlength")
@Override
public ModelBuildingResult build(ModelBuildingRequest request) throws ModelBuildingException {
- return build(request, new LinkedHashSet<>());
+ return build(request, new LinkedHashSet());
}
+ @SuppressWarnings("checkstyle:methodlength")
protected ModelBuildingResult build(ModelBuildingRequest request, Collection importIds)
throws ModelBuildingException {
// phase 1
@@ -697,32 +259,13 @@ public class DefaultModelBuilder implements ModelBuilder {
DefaultModelProblemCollector problems = new DefaultModelProblemCollector(result);
// read and validate raw model
- Model fileModel = readFileModel(request, problems);
-
- request.setFileModel(fileModel);
- result.setFileModel(fileModel.clone());
-
- activateFileModel(request, result, problems);
-
- if (!request.isTwoPhaseBuilding()) {
- return build(request, result, importIds);
- } else if (hasModelErrors(problems)) {
- throw problems.newModelBuildingException();
+ Model inputModel = request.getRawModel();
+ if (inputModel == null) {
+ inputModel = readModel(request.getModelSource(), request.getPomFile(), request, problems);
}
- return result;
- }
-
- private void activateFileModel(
- final ModelBuildingRequest request,
- final DefaultModelBuildingResult result,
- DefaultModelProblemCollector problems)
- throws ModelBuildingException {
- Model inputModel = request.getFileModel();
- problems.setRootModel(inputModel);
-
// profile activation
- DefaultProfileActivationContext profileActivationContext = getProfileActivationContext(request);
+ DefaultProfileActivationContext profileActivationContext = getProfileActivationContext(request, inputModel);
problems.setSource("(external profiles)");
List activeExternalProfiles =
@@ -739,124 +282,90 @@ public class DefaultModelBuilder implements ModelBuilder {
profileActivationContext.setUserProperties(profileProps);
}
- profileActivationContext.setProjectProperties(inputModel.getDelegate().getProperties());
- problems.setSource(inputModel);
- List activePomProfiles =
- profileSelector.getActiveProfiles(inputModel.getProfiles(), profileActivationContext, problems);
-
- // model normalization
- problems.setSource(inputModel);
- inputModel.update(modelNormalizer.mergeDuplicates(inputModel.getDelegate(), request, problems));
-
- Map interpolatedActivations = getProfileActivations(inputModel, false);
- injectProfileActivations(inputModel, interpolatedActivations);
-
- // profile injection
- for (Profile activeProfile : activePomProfiles) {
- profileInjector.injectProfile(inputModel, activeProfile, request, problems);
- }
-
- modelValidator.validateExternalProfiles(activeExternalProfiles, inputModel, request, problems);
- for (Profile activeProfile : activeExternalProfiles) {
- profileInjector.injectProfile(inputModel, activeProfile, request, problems);
- }
- }
-
- @SuppressWarnings("checkstyle:methodlength")
- private Model readEffectiveModel(
- final ModelBuildingRequest request,
- final DefaultModelBuildingResult result,
- DefaultModelProblemCollector problems)
- throws ModelBuildingException {
- Model inputModel = readRawModel(request, problems);
- if (problems.hasFatalErrors()) {
- throw problems.newModelBuildingException();
- }
-
problems.setRootModel(inputModel);
ModelData resultData = new ModelData(request.getModelSource(), inputModel);
- String superModelVersion =
- inputModel.getModelVersion() != null ? inputModel.getModelVersion() : MODEL_VERSION_4_0_0;
- if (!DefaultModelValidator.VALID_MODEL_VERSIONS.contains(superModelVersion)) {
- // Maven 3.x is always using 4.0.0 version to load the supermodel, so
- // do the same when loading a dependency. The model validator will also
- // check that field later.
- superModelVersion = MODEL_VERSION_4_0_0;
- }
- ModelData superData = new ModelData(null, getSuperModel(superModelVersion));
-
- // profile activation
- DefaultProfileActivationContext profileActivationContext = getProfileActivationContext(request);
-
- List activeExternalProfiles = result.getActiveExternalProfiles();
-
- if (!activeExternalProfiles.isEmpty()) {
- Properties profileProps = new Properties();
- for (Profile profile : activeExternalProfiles) {
- profileProps.putAll(profile.getProperties());
- }
- profileProps.putAll(profileActivationContext.getUserProperties());
- profileActivationContext.setUserProperties(profileProps);
- }
+ ModelData superData = new ModelData(null, getSuperModel());
Collection parentIds = new LinkedHashSet<>();
+ List lineage = new ArrayList<>();
- List lineage = new ArrayList<>();
+ for (ModelData currentData = resultData; currentData != null; ) {
+ lineage.add(currentData);
- for (ModelData currentData = resultData; ; ) {
- String modelId = currentData.getId();
- result.addModelId(modelId);
+ Model rawModel = currentData.getModel();
+ currentData.setRawModel(rawModel);
- Model model = currentData.getModel();
- result.setRawModel(modelId, model);
- problems.setSource(model);
- org.apache.maven.api.model.Model modelv4 = model.getDelegate();
+ Model tmpModel = rawModel.clone();
+ currentData.setModel(tmpModel);
+
+ problems.setSource(tmpModel);
// model normalization
- modelv4 = modelNormalizer.mergeDuplicates(modelv4, request, problems);
+ modelNormalizer.mergeDuplicates(tmpModel, request, problems);
- // profile activation
- profileActivationContext.setProjectProperties(modelv4.getProperties());
+ profileActivationContext.setProjectProperties(tmpModel.getProperties());
- List interpolatedProfiles =
- interpolateActivations(modelv4.getProfiles(), profileActivationContext, problems);
+ List interpolatedProfiles = getInterpolatedProfiles(rawModel, profileActivationContext, problems);
+ tmpModel.setProfiles(interpolatedProfiles);
+
+ List activePomProfiles =
+ profileSelector.getActiveProfiles(tmpModel.getProfiles(), profileActivationContext, problems);
+
+ List rawProfiles = new ArrayList<>();
+ for (Profile activePomProfile : activePomProfiles) {
+ rawProfiles.add(rawModel.getProfiles().get(interpolatedProfiles.indexOf(activePomProfile)));
+ }
+ currentData.setActiveProfiles(rawProfiles);
// profile injection
- List activePomProfiles =
- profileSelector.getActiveProfilesV4(interpolatedProfiles, profileActivationContext, problems);
- result.setActivePomProfiles(
- modelId, activePomProfiles.stream().map(Profile::new).collect(Collectors.toList()));
- modelv4 = profileInjector.injectProfiles(modelv4, activePomProfiles, request, problems);
- if (currentData == resultData) {
- for (Profile activeProfile : activeExternalProfiles) {
- modelv4 = profileInjector.injectProfile(modelv4, activeProfile.getDelegate(), request, problems);
- }
+ for (Profile activeProfile : activePomProfiles) {
+ profileInjector.injectProfile(tmpModel, activeProfile, request, problems);
}
- lineage.add(new Model(modelv4));
+ if (currentData == resultData) {
+ for (Profile activeProfile : activeExternalProfiles) {
+ profileInjector.injectProfile(tmpModel, activeProfile, request, problems);
+ }
+ }
if (currentData == superData) {
break;
}
- // add repositories specified by the current model so that we can resolve the parent
- configureResolver(request.getModelResolver(), modelv4, problems, false);
+ configureResolver(request.getModelResolver(), tmpModel, problems);
- // we pass a cloned model, so that resolving the parent version does not affect the returned model
- ModelData parentData = readParent(new Model(modelv4), currentData.getSource(), request, problems);
+ ModelData parentData = readParent(tmpModel, currentData.getSource(), request, problems);
if (parentData == null) {
currentData = superData;
+ } else if (currentData == resultData) { // First iteration - add initial id after version resolution.
+ currentData.setGroupId(
+ currentData.getRawModel().getGroupId() == null
+ ? parentData.getGroupId()
+ : currentData.getRawModel().getGroupId());
+
+ currentData.setVersion(
+ currentData.getRawModel().getVersion() == null
+ ? parentData.getVersion()
+ : currentData.getRawModel().getVersion());
+
+ currentData.setArtifactId(currentData.getRawModel().getArtifactId());
+ parentIds.add(currentData.getId());
+ // Reset - only needed for 'getId'.
+ currentData.setGroupId(null);
+ currentData.setArtifactId(null);
+ currentData.setVersion(null);
+ currentData = parentData;
} else if (!parentIds.add(parentData.getId())) {
- StringBuilder message = new StringBuilder("The parents form a cycle: ");
- for (String parentId : parentIds) {
- message.append(parentId).append(" -> ");
+ String message = "The parents form a cycle: ";
+ for (String modelId : parentIds) {
+ message += modelId + " -> ";
}
- message.append(parentData.getId());
+ message += parentData.getId();
problems.add(new ModelProblemCollectorRequest(ModelProblem.Severity.FATAL, ModelProblem.Version.BASE)
- .setMessage(message.toString()));
+ .setMessage(message));
throw problems.newModelBuildingException();
} else {
@@ -864,166 +373,144 @@ public class DefaultModelBuilder implements ModelBuilder {
}
}
- Model tmpModel = lineage.get(0);
-
- // inject interpolated activations
- List interpolated =
- interpolateActivations(tmpModel.getDelegate().getProfiles(), profileActivationContext, problems);
- if (interpolated != tmpModel.getDelegate().getProfiles()) {
- tmpModel.update(tmpModel.getDelegate().withProfiles(interpolated));
- }
-
- // inject external profile into current model
- tmpModel.update(profileInjector.injectProfiles(
- tmpModel.getDelegate(),
- activeExternalProfiles.stream().map(Profile::getDelegate).collect(Collectors.toList()),
- request,
- problems));
-
+ problems.setSource(inputModel);
checkPluginVersions(lineage, request, problems);
// inheritance assembly
- Model resultModel = assembleInheritance(lineage, request, problems);
+ assembleInheritance(lineage, request, problems);
- // consider caching inherited model
+ Model resultModel = resultData.getModel();
problems.setSource(resultModel);
problems.setRootModel(resultModel);
// model interpolation
resultModel = interpolateModel(resultModel, request, problems);
+ resultData.setModel(resultModel);
+
+ if (resultModel.getParent() != null) {
+ final ModelData parentData = lineage.get(1);
+ if (parentData.getVersion() == null || parentData.getVersion().contains("${")) {
+ final Model interpolatedParent = interpolateModel(parentData.getModel(), request, problems);
+ // parentData.setModel( interpolatedParent );
+ parentData.setVersion(interpolatedParent.getVersion());
+ }
+ }
// url normalization
modelUrlNormalizer.normalize(resultModel, request);
+ // Now the fully interpolated model is available: reconfigure the resolver
+ configureResolver(request.getModelResolver(), resultModel, problems, true);
+
+ resultData.setGroupId(resultModel.getGroupId());
+ resultData.setArtifactId(resultModel.getArtifactId());
+ resultData.setVersion(resultModel.getVersion());
+
result.setEffectiveModel(resultModel);
- // Now the fully interpolated model is available: reconfigure the resolver
- configureResolver(request.getModelResolver(), resultModel.getDelegate(), problems, true);
+ for (ModelData currentData : lineage) {
+ String modelId = (currentData != superData) ? currentData.getId() : "";
- return resultModel;
+ result.addModelId(modelId);
+ result.setActivePomProfiles(modelId, currentData.getActiveProfiles());
+ result.setRawModel(modelId, currentData.getRawModel());
+ }
+
+ if (!request.isTwoPhaseBuilding()) {
+ build(request, result, importIds);
+ }
+
+ return result;
}
- private List interpolateActivations(
- List profiles,
- DefaultProfileActivationContext context,
- DefaultModelProblemCollector problems) {
- if (profiles.stream()
- .map(org.apache.maven.api.model.Profile::getActivation)
- .noneMatch(Objects::nonNull)) {
- return profiles;
+ @FunctionalInterface
+ private interface InterpolateString {
+ String apply(String s) throws InterpolationException;
+ }
+
+ private List getInterpolatedProfiles(
+ Model rawModel, DefaultProfileActivationContext context, DefaultModelProblemCollector problems) {
+ List interpolatedActivations = getProfiles(rawModel, true);
+
+ if (interpolatedActivations.isEmpty()) {
+ return Collections.emptyList();
}
- final Interpolator xform = new RegexBasedInterpolator();
- xform.setCacheAnswers(true);
- Stream.of(context.getUserProperties(), context.getSystemProperties())
- .map(MapBasedValueSource::new)
- .forEach(xform::addValueSource);
+ RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
- class ProfileInterpolator extends MavenTransformer
- implements UnaryOperator {
- ProfileInterpolator() {
- super(s -> {
- if (isNotEmpty(s)) {
- try {
- return xform.interpolate(s);
- } catch (InterpolationException e) {
- problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
- .setMessage(e.getMessage())
- .setException(e));
- }
- }
- return s;
- });
+ interpolator.addValueSource(new MapBasedValueSource(context.getProjectProperties()));
+ interpolator.addValueSource(new MapBasedValueSource(context.getUserProperties()));
+ interpolator.addValueSource(new MapBasedValueSource(context.getSystemProperties()));
+
+ class Interpolation {
+ final InputLocationTracker target;
+
+ final InterpolateString impl;
+
+ Interpolation(InputLocationTracker target, InterpolateString impl) {
+ this.target = target;
+ this.impl = impl;
}
- @Override
- public org.apache.maven.api.model.Profile apply(org.apache.maven.api.model.Profile p) {
- return org.apache.maven.api.model.Profile.newBuilder(p)
- .activation(transformActivation(p.getActivation()))
- .build();
- }
-
- @Override
- protected ActivationFile.Builder transformActivationFile_Missing(
- Supplier extends ActivationFile.Builder> creator,
- ActivationFile.Builder builder,
- ActivationFile target) {
- final String path = target.getMissing();
- final String xformed = transformPath(path, target, "missing");
- return xformed != path ? (builder != null ? builder : creator.get()).missing(xformed) : builder;
- }
-
- @Override
- protected ActivationFile.Builder transformActivationFile_Exists(
- Supplier extends ActivationFile.Builder> creator,
- ActivationFile.Builder builder,
- ActivationFile target) {
- final String path = target.getExists();
- final String xformed = transformPath(path, target, "exists");
- return xformed != path ? (builder != null ? builder : creator.get()).exists(xformed) : builder;
- }
-
- private String transformPath(String path, ActivationFile target, String locationKey) {
- if (isNotEmpty(path)) {
- try {
- return profileActivationFilePathInterpolator.interpolate(path, context);
- } catch (InterpolationException e) {
- addInterpolationProblem(problems, target, path, e, locationKey);
- }
+ void performFor(String value, String locationKey, Consumer mutator) {
+ if (StringUtils.isEmpty(value)) {
+ return;
+ }
+ try {
+ mutator.accept(impl.apply(value));
+ } catch (InterpolationException e) {
+ problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
+ .setMessage("Failed to interpolate value " + value + ": " + e.getMessage())
+ .setLocation(target.getLocation(locationKey))
+ .setException(e));
}
- return path;
}
}
- return profiles.stream().map(new ProfileInterpolator()).toList();
- }
-
- private static void addInterpolationProblem(
- DefaultModelProblemCollector problems,
- org.apache.maven.api.model.InputLocationTracker target,
- String path,
- InterpolationException e,
- String locationKey) {
- problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
- .setMessage("Failed to interpolate file location " + path + ": " + e.getMessage())
- .setLocation(Optional.ofNullable(target.getLocation(locationKey))
- .map(InputLocation::new)
- .orElse(null))
- .setException(e));
- }
-
- private static boolean isNotEmpty(String string) {
- return string != null && !string.isEmpty();
+ for (Profile profile : interpolatedActivations) {
+ Activation activation = profile.getActivation();
+ Optional a = Optional.ofNullable(activation);
+ a.map(Activation::getFile).ifPresent(fa -> {
+ Interpolation nt =
+ new Interpolation(fa, s -> profileActivationFilePathInterpolator.interpolate(s, context));
+ nt.performFor(fa.getExists(), "exists", fa::setExists);
+ nt.performFor(fa.getMissing(), "missing", fa::setMissing);
+ });
+ a.map(Activation::getOs).ifPresent(oa -> {
+ Interpolation nt = new Interpolation(oa, interpolator::interpolate);
+ nt.performFor(oa.getArch(), "arch", oa::setArch);
+ nt.performFor(oa.getFamily(), "family", oa::setFamily);
+ nt.performFor(oa.getName(), "name", oa::setName);
+ nt.performFor(oa.getVersion(), "version", oa::setVersion);
+ });
+ a.map(Activation::getProperty).ifPresent(pa -> {
+ Interpolation nt = new Interpolation(pa, interpolator::interpolate);
+ nt.performFor(pa.getName(), "name", pa::setName);
+ nt.performFor(pa.getValue(), "value", pa::setValue);
+ });
+ a.map(Activation::getJdk).ifPresent(ja -> new Interpolation(activation, interpolator::interpolate)
+ .performFor(ja, "jdk", activation::setJdk));
+ }
+ return interpolatedActivations;
}
@Override
- public ModelBuildingResult build(final ModelBuildingRequest request, final ModelBuildingResult result)
+ public ModelBuildingResult build(ModelBuildingRequest request, ModelBuildingResult result)
throws ModelBuildingException {
- return build(request, result, new LinkedHashSet<>());
- }
-
- public Model buildRawModel(final ModelBuildingRequest request) throws ModelBuildingException {
- DefaultModelProblemCollector problems = new DefaultModelProblemCollector(new DefaultModelBuildingResult());
- Model model = readRawModel(request, problems);
- if (hasModelErrors(problems)) {
- throw problems.newModelBuildingException();
- }
- return model;
+ return build(request, result, new LinkedHashSet());
}
private ModelBuildingResult build(
- final ModelBuildingRequest request, final ModelBuildingResult phaseOneResult, Collection imports)
+ ModelBuildingRequest request, ModelBuildingResult result, Collection imports)
throws ModelBuildingException {
- DefaultModelBuildingResult result = asDefaultModelBuildingResult(phaseOneResult);
+ // phase 2
+ Model resultModel = result.getEffectiveModel();
DefaultModelProblemCollector problems = new DefaultModelProblemCollector(result);
-
- // phase 2
- Model resultModel = readEffectiveModel(request, result, problems);
problems.setSource(resultModel);
problems.setRootModel(resultModel);
// model path translation
- modelPathTranslator.alignToBaseDirectory(resultModel, resultModel.getProjectDirectoryPath(), request);
+ modelPathTranslator.alignToBaseDirectory(resultModel, resultModel.getProjectDirectory(), request);
// plugin management injection
pluginManagementInjector.injectManagement(resultModel, request, problems);
@@ -1045,12 +532,15 @@ public class DefaultModelBuilder implements ModelBuilder {
// dependency management injection
dependencyManagementInjector.injectManagement(resultModel, request, problems);
- resultModel.update(modelNormalizer.injectDefaultValues(resultModel.getDelegate(), request, problems));
+ modelNormalizer.injectDefaultValues(resultModel, request, problems);
if (request.isProcessPlugins()) {
// reports configuration
reportConfigurationExpander.expandPluginConfiguration(resultModel, request, problems);
+ // reports conversion to decoupled site plugin
+ reportingConverter.convertReporting(resultModel, request, problems);
+
// plugins configuration
pluginConfigurationExpander.expandPluginConfiguration(resultModel, request, problems);
}
@@ -1065,104 +555,45 @@ public class DefaultModelBuilder implements ModelBuilder {
return result;
}
- private DefaultModelBuildingResult asDefaultModelBuildingResult(ModelBuildingResult phaseOneResult) {
- if (phaseOneResult instanceof DefaultModelBuildingResult) {
- return (DefaultModelBuildingResult) phaseOneResult;
- } else {
- return new DefaultModelBuildingResult(phaseOneResult);
- }
- }
-
- @Deprecated
@Override
public Result extends Model> buildRawModel(File pomFile, int validationLevel, boolean locationTracking) {
- return buildRawModel(pomFile.toPath(), validationLevel, locationTracking, null);
- }
-
- @Override
- public Result extends Model> buildRawModel(Path pomFile, int validationLevel, boolean locationTracking) {
- return buildRawModel(pomFile, validationLevel, locationTracking, null);
- }
-
- @Deprecated
- @Override
- public Result extends Model> buildRawModel(
- File pomFile, int validationLevel, boolean locationTracking, TransformerContext context) {
- return buildRawModel(pomFile.toPath(), validationLevel, locationTracking, context);
- }
-
- @Override
- public Result extends Model> buildRawModel(
- Path pomFile, int validationLevel, boolean locationTracking, TransformerContext context) {
final ModelBuildingRequest request = new DefaultModelBuildingRequest()
.setValidationLevel(validationLevel)
- .setLocationTracking(locationTracking)
- .setModelSource(new FileModelSource(pomFile));
- DefaultModelProblemCollector problems = new DefaultModelProblemCollector(new DefaultModelBuildingResult());
+ .setLocationTracking(locationTracking);
+ final DefaultModelProblemCollector collector =
+ new DefaultModelProblemCollector(new DefaultModelBuildingResult());
try {
- Model model = readFileModel(request, problems);
-
- try {
- if (transformer != null && context != null) {
- transformer.transform(pomFile, context, model);
- }
- } catch (TransformerException e) {
- problems.add(
- new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V40).setException(e));
- }
-
- return newResult(model, problems.getProblems());
+ return newResult(readModel(null, pomFile, request, collector), collector.getProblems());
} catch (ModelBuildingException e) {
- return error(problems.getProblems());
+ return error(collector.getProblems());
}
}
- Model readFileModel(ModelBuildingRequest request, DefaultModelProblemCollector problems)
+ private Model readModel(
+ ModelSource modelSource, File pomFile, ModelBuildingRequest request, DefaultModelProblemCollector problems)
throws ModelBuildingException {
- ModelSource modelSource = request.getModelSource();
- org.apache.maven.api.model.Model model = cache(
- request.getModelCache(),
- modelSource,
- ModelCacheTag.FILE,
- () -> doReadFileModel(modelSource, request, problems));
+ Model model;
- if (modelSource instanceof FileModelSource) {
- if (request.getTransformerContextBuilder() instanceof DefaultTransformerContextBuilder) {
- DefaultTransformerContextBuilder contextBuilder =
- (DefaultTransformerContextBuilder) request.getTransformerContextBuilder();
- contextBuilder.putSource(getGroupId(model), model.getArtifactId(), (FileModelSource) modelSource);
+ if (modelSource == null) {
+ if (pomFile != null) {
+ modelSource = new FileModelSource(pomFile);
+ } else {
+ throw new NullPointerException("neither pomFile nor modelSource can be null");
}
}
- return new Model(model);
- }
-
- @SuppressWarnings("checkstyle:methodlength")
- private org.apache.maven.api.model.Model doReadFileModel(
- ModelSource modelSource, ModelBuildingRequest request, DefaultModelProblemCollector problems)
- throws ModelBuildingException {
- org.apache.maven.api.model.Model model;
problems.setSource(modelSource.getLocation());
try {
boolean strict = request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0;
+ InputSource source = request.isLocationTracking() ? new InputSource() : null;
- Map options = new HashMap<>(3);
+ Map options = new HashMap<>();
options.put(ModelProcessor.IS_STRICT, strict);
+ options.put(ModelProcessor.INPUT_SOURCE, source);
options.put(ModelProcessor.SOURCE, modelSource);
- options.put(ModelReader.ROOT_DIRECTORY, request.getRootDirectory());
-
- InputSource source;
- if (request.isLocationTracking()) {
- source = new InputSource(null, modelSource.getLocation());
- options.put(ModelProcessor.INPUT_SOURCE, new org.apache.maven.model.InputSource(source));
- } else {
- source = null;
- }
try {
- model = modelProcessor
- .read(modelSource.getInputStream(), options)
- .getDelegate();
+ model = modelProcessor.read(modelSource.getInputStream(), options);
} catch (ModelParseException e) {
if (!strict) {
throw e;
@@ -1171,42 +602,35 @@ public class DefaultModelBuilder implements ModelBuilder {
options.put(ModelProcessor.IS_STRICT, Boolean.FALSE);
try {
- model = modelProcessor
- .read(modelSource.getInputStream(), options)
- .getDelegate();
+ model = modelProcessor.read(modelSource.getInputStream(), options);
} catch (ModelParseException ne) {
// still unreadable even in non-strict mode, rethrow original error
throw e;
}
- Severity severity = (modelSource instanceof FileModelSource) ? Severity.ERROR : Severity.WARNING;
- problems.add(new ModelProblemCollectorRequest(severity, ModelProblem.Version.V20)
- .setMessage("Malformed POM " + modelSource.getLocation() + ": " + e.getMessage())
- .setException(e));
+ if (pomFile != null) {
+ problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.V20)
+ .setMessage("Malformed POM " + modelSource.getLocation() + ": " + e.getMessage())
+ .setException(e));
+ } else {
+ problems.add(new ModelProblemCollectorRequest(Severity.WARNING, Version.V20)
+ .setMessage("Malformed POM " + modelSource.getLocation() + ": " + e.getMessage())
+ .setException(e));
+ }
}
if (source != null) {
- try {
- org.apache.maven.api.model.InputLocation loc = model.getLocation("");
- org.apache.maven.api.model.InputSource v4src = loc != null ? loc.getSource() : null;
- if (v4src != null) {
- Field field = InputSource.class.getDeclaredField("modelId");
- field.setAccessible(true);
- field.set(v4src, ModelProblemUtils.toId(model));
- }
- } catch (Throwable t) {
- // TODO: use a lazy source ?
- throw new IllegalStateException("Unable to set modelId on InputSource", t);
- }
+ source.setModelId(ModelProblemUtils.toId(model));
+ source.setLocation(modelSource.getLocation());
}
} catch (ModelParseException e) {
- problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.BASE)
+ problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
.setMessage("Non-parseable POM " + modelSource.getLocation() + ": " + e.getMessage())
.setException(e));
throw problems.newModelBuildingException();
} catch (IOException e) {
String msg = e.getMessage();
- if (msg == null || msg.isEmpty()) {
+ if (msg == null || msg.length() <= 0) {
// NOTE: There's java.nio.charset.MalformedInputException and sun.io.MalformedInputException
if (e.getClass().getName().endsWith("MalformedInputException")) {
msg = "Some input bytes do not match the file encoding.";
@@ -1214,21 +638,16 @@ public class DefaultModelBuilder implements ModelBuilder {
msg = e.getClass().getSimpleName();
}
}
- problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.BASE)
+ problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
.setMessage("Non-readable POM " + modelSource.getLocation() + ": " + msg)
.setException(e));
throw problems.newModelBuildingException();
}
- if (modelSource instanceof FileModelSource) {
- model = model.withPomFile(((FileModelSource) modelSource).getPath());
- }
+ model.setPomFile(pomFile);
- Model retModel = new Model(model);
-
- problems.setSource(retModel);
-
- modelValidator.validateFileModel(retModel, request, problems);
+ problems.setSource(model);
+ modelValidator.validateRawModel(model, request, problems);
if (hasFatalErrors(problems)) {
throw problems.newModelBuildingException();
@@ -1237,80 +656,7 @@ public class DefaultModelBuilder implements ModelBuilder {
return model;
}
- Model readRawModel(ModelBuildingRequest request, DefaultModelProblemCollector problems)
- throws ModelBuildingException {
- ModelSource modelSource = request.getModelSource();
-
- ModelData modelData = cache(
- request.getModelCache(),
- modelSource,
- ModelCacheTag.RAW,
- () -> doReadRawModel(modelSource, request, problems));
-
- return modelData.getModel();
- }
-
- private ModelData doReadRawModel(
- ModelSource modelSource, ModelBuildingRequest request, DefaultModelProblemCollector problems)
- throws ModelBuildingException {
- Model rawModel;
- if (modelSource instanceof FileModelSource) {
- rawModel = readFileModel(request, problems);
-
- if (!MODEL_VERSION_4_0_0.equals(rawModel.getModelVersion())) {
- File pomFile = ((FileModelSource) modelSource).getFile();
-
- try {
- if (request.getTransformerContextBuilder() != null) {
- TransformerContext context =
- request.getTransformerContextBuilder().initialize(request, problems);
- transformer.transform(pomFile.toPath(), context, rawModel);
- }
- } catch (TransformerException e) {
- problems.add(
- new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V40).setException(e));
- }
- }
- } else if (request.getFileModel() == null) {
- rawModel = readFileModel(request, problems);
- } else {
- rawModel = request.getFileModel().clone();
- }
-
- modelValidator.validateRawModel(rawModel, request, problems);
-
- if (hasFatalErrors(problems)) {
- throw problems.newModelBuildingException();
- }
-
- String groupId = getGroupId(rawModel);
- String artifactId = rawModel.getArtifactId();
- String version = getVersion(rawModel);
-
- return new ModelData(modelSource, rawModel, groupId, artifactId, version);
- }
-
- String getGroupId(Model model) {
- return getGroupId(model.getDelegate());
- }
-
- private String getGroupId(org.apache.maven.api.model.Model model) {
- String groupId = model.getGroupId();
- if (groupId == null && model.getParent() != null) {
- groupId = model.getParent().getGroupId();
- }
- return groupId;
- }
-
- private String getVersion(Model model) {
- String version = model.getVersion();
- if (version == null && model.getParent() != null) {
- version = model.getParent().getVersion();
- }
- return version;
- }
-
- private DefaultProfileActivationContext getProfileActivationContext(ModelBuildingRequest request) {
+ private DefaultProfileActivationContext getProfileActivationContext(ModelBuildingRequest request, Model rawModel) {
DefaultProfileActivationContext context = new DefaultProfileActivationContext();
context.setActiveProfileIds(request.getActiveProfileIds());
@@ -1318,11 +664,8 @@ public class DefaultModelBuilder implements ModelBuilder {
context.setSystemProperties(request.getSystemProperties());
// enrich user properties with project packaging
Properties userProperties = request.getUserProperties();
- if (!userProperties.containsKey(ProfileActivationContext.PROPERTY_NAME_PACKAGING)) {
- userProperties.put(
- ProfileActivationContext.PROPERTY_NAME_PACKAGING,
- request.getFileModel().getPackaging());
- }
+ userProperties.computeIfAbsent(
+ (Object) ProfileActivationContext.PROPERTY_NAME_PACKAGING, (p) -> (Object) rawModel.getPackaging());
context.setUserProperties(userProperties);
context.setProjectDirectory(
(request.getPomFile() != null) ? request.getPomFile().getParentFile() : null);
@@ -1330,27 +673,37 @@ public class DefaultModelBuilder implements ModelBuilder {
return context;
}
+ private void configureResolver(ModelResolver modelResolver, Model model, DefaultModelProblemCollector problems) {
+ configureResolver(modelResolver, model, problems, false);
+ }
+
private void configureResolver(
ModelResolver modelResolver,
- org.apache.maven.api.model.Model model,
+ Model model,
DefaultModelProblemCollector problems,
boolean replaceRepositories) {
- if (modelResolver != null) {
- for (org.apache.maven.api.model.Repository repository : model.getRepositories()) {
- try {
- modelResolver.addRepository(repository, replaceRepositories);
- } catch (InvalidRepositoryException e) {
- problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
- .setMessage("Invalid repository " + repository.getId() + ": " + e.getMessage())
- .setLocation(new InputLocation(repository.getLocation("")))
- .setException(e));
- }
+ if (modelResolver == null) {
+ return;
+ }
+
+ problems.setSource(model);
+
+ List repositories = model.getRepositories();
+
+ for (Repository repository : repositories) {
+ try {
+ modelResolver.addRepository(repository, replaceRepositories);
+ } catch (InvalidRepositoryException e) {
+ problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
+ .setMessage("Invalid repository " + repository.getId() + ": " + e.getMessage())
+ .setLocation(repository.getLocation(""))
+ .setException(e));
}
}
}
private void checkPluginVersions(
- List lineage, ModelBuildingRequest request, ModelProblemCollector problems) {
+ List lineage, ModelBuildingRequest request, ModelProblemCollector problems) {
if (request.getValidationLevel() < ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0) {
return;
}
@@ -1360,7 +713,7 @@ public class DefaultModelBuilder implements ModelBuilder {
Map managedVersions = new HashMap<>();
for (int i = lineage.size() - 1; i >= 0; i--) {
- Model model = lineage.get(i);
+ Model model = lineage.get(i).getModel();
Build build = model.getBuild();
if (build != null) {
for (Plugin plugin : build.getPlugins()) {
@@ -1374,7 +727,9 @@ public class DefaultModelBuilder implements ModelBuilder {
if (mgmt != null) {
for (Plugin plugin : mgmt.getPlugins()) {
String key = plugin.getKey();
- managedVersions.computeIfAbsent(key, k -> plugin.getVersion());
+ if (managedVersions.get(key) == null) {
+ managedVersions.put(key, plugin.getVersion());
+ }
}
}
}
@@ -1383,62 +738,39 @@ public class DefaultModelBuilder implements ModelBuilder {
for (String key : versions.keySet()) {
if (versions.get(key) == null && managedVersions.get(key) == null) {
InputLocation location = plugins.get(key).getLocation("");
- problems.add(new ModelProblemCollectorRequest(Severity.WARNING, ModelProblem.Version.V20)
+ problems.add(new ModelProblemCollectorRequest(Severity.WARNING, Version.V20)
.setMessage("'build.plugins.plugin.version' for " + key + " is missing.")
.setLocation(location));
}
}
}
- private Model assembleInheritance(
- List lineage, ModelBuildingRequest request, ModelProblemCollector problems) {
- org.apache.maven.api.model.Model parent =
- lineage.get(lineage.size() - 1).getDelegate();
+ private void assembleInheritance(
+ List lineage, ModelBuildingRequest request, ModelProblemCollector problems) {
for (int i = lineage.size() - 2; i >= 0; i--) {
- Model child = lineage.get(i);
- parent = inheritanceAssembler.assembleModelInheritance(child.getDelegate(), parent, request, problems);
+ Model parent = lineage.get(i + 1).getModel();
+ Model child = lineage.get(i).getModel();
+ inheritanceAssembler.assembleModelInheritance(child, parent, request, problems);
}
- return new Model(parent);
}
- private Map getProfileActivations(Model model, boolean clone) {
- Map activations = new HashMap<>();
+ private List getProfiles(Model model, boolean clone) {
+ ArrayList profiles = new ArrayList<>();
for (Profile profile : model.getProfiles()) {
- Activation activation = profile.getActivation();
-
- if (activation == null) {
- continue;
- }
-
if (clone) {
- activation = activation.clone();
+ profile = profile.clone();
}
-
- activations.put(profile.getId(), activation);
- }
-
- return activations;
- }
-
- private void injectProfileActivations(Model model, Map activations) {
- for (Profile profile : model.getProfiles()) {
- Activation activation = profile.getActivation();
-
- if (activation == null) {
- continue;
- }
-
- // restore activation
- profile.setActivation(activations.get(profile.getId()));
+ profiles.add(profile);
}
+ return profiles;
}
private Model interpolateModel(Model model, ModelBuildingRequest request, ModelProblemCollector problems) {
// save profile activations before interpolation, since they are evaluated with limited scope
- Map originalActivations = getProfileActivations(model, true);
+ List originalProfiles = getProfiles(model, true);
- Model interpolatedModel = new Model(modelInterpolator.interpolateModel(
- model.getDelegate(), model.getProjectDirectoryPath(), request, problems));
+ Model interpolatedModel =
+ modelInterpolator.interpolateModel(model, model.getProjectDirectory(), request, problems);
if (interpolatedModel.getParent() != null) {
StringSearchInterpolator ssi = new StringSearchInterpolator();
ssi.addValueSource(new MapBasedValueSource(request.getUserProperties()));
@@ -1452,8 +784,7 @@ public class DefaultModelBuilder implements ModelBuilder {
ssi.interpolate(interpolatedModel.getParent().getVersion());
interpolatedModel.getParent().setVersion(interpolated);
} catch (Exception e) {
- ModelProblemCollectorRequest mpcr = new ModelProblemCollectorRequest(
- Severity.ERROR, ModelProblem.Version.BASE)
+ ModelProblemCollectorRequest mpcr = new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
.setMessage("Failed to interpolate field: "
+ interpolatedModel.getParent().getVersion()
+ " on class: ")
@@ -1461,43 +792,86 @@ public class DefaultModelBuilder implements ModelBuilder {
problems.add(mpcr);
}
}
- interpolatedModel.setPomPath(model.getPomPath());
+ interpolatedModel.setPomFile(model.getPomFile());
- // restore profiles with file activation to their value before full interpolation
- injectProfileActivations(model, originalActivations);
+ // restore profiles with any activation to their value before full interpolation
+ List interpolatedProfiles = model.getProfiles();
+ IntStream.range(0, interpolatedProfiles.size()).forEach(i -> interpolatedProfiles
+ .get(i)
+ .setActivation(originalProfiles.get(i).getActivation()));
return interpolatedModel;
}
private ModelData readParent(
- Model childModel, Source childSource, ModelBuildingRequest request, DefaultModelProblemCollector problems)
+ Model childModel,
+ ModelSource childSource,
+ ModelBuildingRequest request,
+ DefaultModelProblemCollector problems)
throws ModelBuildingException {
- ModelData parentData = null;
+ ModelData parentData;
Parent parent = childModel.getParent();
+
if (parent != null) {
- parentData = readParentLocally(childModel, childSource, request, problems);
+ String groupId = parent.getGroupId();
+ String artifactId = parent.getArtifactId();
+ String version = parent.getVersion();
+
+ parentData = getCache(request.getModelCache(), groupId, artifactId, version, ModelCacheTag.RAW);
+
if (parentData == null) {
- parentData = readParentExternally(childModel, request, problems);
+ parentData = readParentLocally(childModel, childSource, request, problems);
+
+ if (parentData == null) {
+ parentData = readParentExternally(childModel, request, problems);
+ }
+
+ putCache(request.getModelCache(), groupId, artifactId, version, ModelCacheTag.RAW, parentData);
+ } else {
+ /*
+ * NOTE: This is a sanity check of the cache hit. If the cached parent POM was locally resolved, the
+ * child's should point at that parent, too. If it doesn't, we ignore the cache and
+ * resolve externally, to mimic the behavior if the cache didn't exist in the first place. Otherwise,
+ * the cache would obscure a bad POM.
+ */
+
+ File pomFile = parentData.getModel().getPomFile();
+ if (pomFile != null) {
+ FileModelSource pomSource = new FileModelSource(pomFile);
+ ModelSource expectedParentSource = getParentPomFile(childModel, childSource);
+
+ if (expectedParentSource == null
+ || (expectedParentSource instanceof ModelSource2
+ && !pomSource.equals(expectedParentSource))) {
+ parentData = readParentExternally(childModel, request, problems);
+ }
+ }
}
Model parentModel = parentData.getModel();
+
if (!"pom".equals(parentModel.getPackaging())) {
- problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
+ problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
.setMessage("Invalid packaging for parent POM " + ModelProblemUtils.toSourceHint(parentModel)
+ ", must be \"pom\" but is \"" + parentModel.getPackaging() + "\"")
.setLocation(parentModel.getLocation("packaging")));
}
+ } else {
+ parentData = null;
}
return parentData;
}
private ModelData readParentLocally(
- Model childModel, Source childSource, ModelBuildingRequest request, DefaultModelProblemCollector problems)
+ Model childModel,
+ ModelSource childSource,
+ ModelBuildingRequest request,
+ DefaultModelProblemCollector problems)
throws ModelBuildingException {
final Parent parent = childModel.getParent();
- final ModelSource2 candidateSource;
+ final ModelSource candidateSource;
final Model candidateModel;
final WorkspaceModelResolver resolver = request.getWorkspaceModelResolver();
if (resolver == null) {
@@ -1507,17 +881,19 @@ public class DefaultModelBuilder implements ModelBuilder {
return null;
}
- ModelBuildingRequest candidateBuildRequest =
- new DefaultModelBuildingRequest(request).setModelSource(candidateSource);
+ File pomFile = null;
+ if (candidateSource instanceof FileModelSource) {
+ pomFile = ((FileModelSource) candidateSource).getPomFile();
+ }
- candidateModel = readRawModel(candidateBuildRequest, problems);
+ candidateModel = readModel(candidateSource, pomFile, request, problems);
} else {
try {
candidateModel =
resolver.resolveRawModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
} catch (UnresolvableModelException e) {
- problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.BASE) //
- .setMessage(e.getMessage())
+ problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE) //
+ .setMessage(e.getMessage().toString())
.setLocation(parent.getLocation(""))
.setException(e));
throw problems.newModelBuildingException();
@@ -1525,7 +901,7 @@ public class DefaultModelBuilder implements ModelBuilder {
if (candidateModel == null) {
return null;
}
- candidateSource = new FileModelSource(candidateModel.getPomPath());
+ candidateSource = new FileModelSource(candidateModel.getPomFile());
}
//
@@ -1534,8 +910,15 @@ public class DefaultModelBuilder implements ModelBuilder {
// before because with parents as ranges it will never work in this scenario.
//
- String groupId = getGroupId(candidateModel);
+ String groupId = candidateModel.getGroupId();
+ if (groupId == null && candidateModel.getParent() != null) {
+ groupId = candidateModel.getParent().getGroupId();
+ }
String artifactId = candidateModel.getArtifactId();
+ String version = candidateModel.getVersion();
+ if (version == null && candidateModel.getParent() != null) {
+ version = candidateModel.getParent().getVersion();
+ }
if (groupId == null
|| !groupId.equals(parent.getGroupId())
@@ -1551,17 +934,19 @@ public class DefaultModelBuilder implements ModelBuilder {
buffer.append(parent.getArtifactId()).append(", please verify your project structure");
problems.setSource(childModel);
- problems.add(new ModelProblemCollectorRequest(Severity.WARNING, ModelProblem.Version.BASE)
+ problems.add(new ModelProblemCollectorRequest(Severity.WARNING, Version.BASE)
.setMessage(buffer.toString())
.setLocation(parent.getLocation("")));
return null;
}
-
- String version = getVersion(candidateModel);
if (version != null && parent.getVersion() != null && !version.equals(parent.getVersion())) {
try {
- VersionRange parentRange = versionParser.parseVersionRange(parent.getVersion());
- if (!parentRange.contains(versionParser.parseVersion(version))) {
+ VersionRange parentRange = VersionRange.createFromVersionSpec(parent.getVersion());
+ if (!parentRange.hasRestrictions()) {
+ // the parent version is not a range, we have version skew, drop back to resolution from repo
+ return null;
+ }
+ if (!parentRange.containsVersion(new DefaultArtifactVersion(version))) {
// version skew drop back to resolution from the repository
return null;
}
@@ -1571,21 +956,21 @@ public class DefaultModelBuilder implements ModelBuilder {
if (rawChildModelVersion == null) {
// Message below is checked for in the MNG-2199 core IT.
- problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V31)
+ problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.V31)
.setMessage("Version must be a constant")
.setLocation(childModel.getLocation("")));
} else {
if (rawChildVersionReferencesParent(rawChildModelVersion)) {
// Message below is checked for in the MNG-2199 core IT.
- problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V31)
+ problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.V31)
.setMessage("Version must be a constant")
.setLocation(childModel.getLocation("version")));
}
}
// MNG-2199: What else to check here ?
- } catch (VersionParserException e) {
+ } catch (InvalidVersionSpecificationException e) {
// invalid version range, so drop back to resolution from the repository
return null;
}
@@ -1600,7 +985,9 @@ public class DefaultModelBuilder implements ModelBuilder {
* if ( version == null || !version.equals( parent.getVersion() ) ) { return null; }
*/
- return new ModelData(candidateSource, candidateModel, groupId, artifactId, version);
+ ModelData parentData = new ModelData(candidateSource, candidateModel, groupId, artifactId, version);
+
+ return parentData;
}
private boolean rawChildVersionReferencesParent(String rawChildModelVersion) {
@@ -1610,24 +997,21 @@ public class DefaultModelBuilder implements ModelBuilder {
|| rawChildModelVersion.equals("${project.parent.version}");
}
- private ModelSource2 getParentPomFile(Model childModel, Source source) {
+ private ModelSource getParentPomFile(Model childModel, ModelSource source) {
if (!(source instanceof ModelSource2)) {
return null;
}
String parentPath = childModel.getParent().getRelativePath();
if (parentPath == null) {
- parentPath = "..";
- childModel.getParent().setRelativePath(parentPath);
- } else if (parentPath.isEmpty()) {
+ parentPath = "../pom.xml";
+ }
+
+ if (parentPath.length() <= 0) {
return null;
}
- if (source instanceof ModelSource3) {
- return ((ModelSource3) source).getRelatedSource(modelProcessor, parentPath);
- } else {
- return ((ModelSource2) source).getRelatedSource(parentPath);
- }
+ return ((ModelSource2) source).getRelatedSource(parentPath);
}
private ModelData readParentExternally(
@@ -1635,7 +1019,7 @@ public class DefaultModelBuilder implements ModelBuilder {
throws ModelBuildingException {
problems.setSource(childModel);
- Parent parent = childModel.getParent();
+ Parent parent = childModel.getParent().clone();
String groupId = parent.getGroupId();
String artifactId = parent.getArtifactId();
@@ -1663,42 +1047,46 @@ public class DefaultModelBuilder implements ModelBuilder {
buffer.append(" for ").append(ModelProblemUtils.toId(childModel));
}
buffer.append(": ").append(e.getMessage());
- if (childModel.getProjectDirectoryPath() != null) {
- if (parent.getRelativePath() == null || parent.getRelativePath().isEmpty()) {
+ if (childModel.getProjectDirectory() != null) {
+ if (parent.getRelativePath() == null || parent.getRelativePath().length() <= 0) {
buffer.append(" and 'parent.relativePath' points at no local POM");
} else {
buffer.append(" and 'parent.relativePath' points at wrong local POM");
}
}
- problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.BASE)
+ problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
.setMessage(buffer.toString())
.setLocation(parent.getLocation(""))
.setException(e));
throw problems.newModelBuildingException();
}
- int validationLevel = Math.min(request.getValidationLevel(), ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0);
- ModelBuildingRequest lenientRequest = new DefaultModelBuildingRequest(request)
- .setValidationLevel(validationLevel)
- .setFileModel(null)
- .setModelSource(modelSource);
+ ModelBuildingRequest lenientRequest = request;
+ if (request.getValidationLevel() > ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0) {
+ lenientRequest = new FilterModelBuildingRequest(request) {
+ @Override
+ public int getValidationLevel() {
+ return ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0;
+ }
+ };
+ }
- Model parentModel = readRawModel(lenientRequest, problems);
+ Model parentModel = readModel(modelSource, null, lenientRequest, problems);
if (!parent.getVersion().equals(version)) {
String rawChildModelVersion = childModel.getVersion();
if (rawChildModelVersion == null) {
// Message below is checked for in the MNG-2199 core IT.
- problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V31)
+ problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.V31)
.setMessage("Version must be a constant")
.setLocation(childModel.getLocation("")));
} else {
if (rawChildVersionReferencesParent(rawChildModelVersion)) {
// Message below is checked for in the MNG-2199 core IT.
- problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.V31)
+ problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.V31)
.setMessage("Version must be a constant")
.setLocation(childModel.getLocation("version")));
}
@@ -1707,14 +1095,17 @@ public class DefaultModelBuilder implements ModelBuilder {
// MNG-2199: What else to check here ?
}
- return new ModelData(
+ ModelData parentData = new ModelData(
modelSource, parentModel, parent.getGroupId(), parent.getArtifactId(), parent.getVersion());
+
+ return parentData;
}
- private Model getSuperModel(String modelVersion) {
- return superPomProvider.getSuperModel(modelVersion);
+ private Model getSuperModel() {
+ return superPomProvider.getSuperModel("4.0.0").clone();
}
+ @SuppressWarnings("checkstyle:methodlength")
private void importDependencyManagement(
Model model,
ModelBuildingRequest request,
@@ -1730,262 +1121,175 @@ public class DefaultModelBuilder implements ModelBuilder {
importIds.add(importing);
- // Model v4
- List importMgmts = new ArrayList<>();
+ final WorkspaceModelResolver workspaceResolver = request.getWorkspaceModelResolver();
+ final ModelResolver modelResolver = request.getModelResolver();
+
+ ModelBuildingRequest importRequest = null;
+
+ List importMgmts = null;
for (Iterator it = depMgmt.getDependencies().iterator(); it.hasNext(); ) {
Dependency dependency = it.next();
- if (!("pom".equals(dependency.getType()) && "import".equals(dependency.getScope()))
- || "bom".equals(dependency.getType())) {
+ if (!"pom".equals(dependency.getType()) || !"import".equals(dependency.getScope())) {
continue;
}
it.remove();
- // Model v3
- DependencyManagement importMgmt = loadDependencyManagement(model, request, problems, dependency, importIds);
- if (importMgmt == null) {
+ String groupId = dependency.getGroupId();
+ String artifactId = dependency.getArtifactId();
+ String version = dependency.getVersion();
+
+ if (groupId == null || groupId.length() <= 0) {
+ problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
+ .setMessage("'dependencyManagement.dependencies.dependency.groupId' for "
+ + dependency.getManagementKey() + " is missing.")
+ .setLocation(dependency.getLocation("")));
+ continue;
+ }
+ if (artifactId == null || artifactId.length() <= 0) {
+ problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
+ .setMessage("'dependencyManagement.dependencies.dependency.artifactId' for "
+ + dependency.getManagementKey() + " is missing.")
+ .setLocation(dependency.getLocation("")));
+ continue;
+ }
+ if (version == null || version.length() <= 0) {
+ problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
+ .setMessage("'dependencyManagement.dependencies.dependency.version' for "
+ + dependency.getManagementKey() + " is missing.")
+ .setLocation(dependency.getLocation("")));
continue;
}
- if (request.isLocationTracking()) {
- // Keep track of why this DependencyManagement was imported.
- // And map model v3 to model v4 -> importMgmt(v3).getDelegate() returns a v4 object
- importMgmts.add(
- org.apache.maven.api.model.DependencyManagement.newBuilder(importMgmt.getDelegate(), true)
- .build());
- } else {
- importMgmts.add(importMgmt.getDelegate());
+ String imported = groupId + ':' + artifactId + ':' + version;
+
+ if (importIds.contains(imported)) {
+ String message = "The dependencies of type=pom and with scope=import form a cycle: ";
+ for (String modelId : importIds) {
+ message += modelId + " -> ";
+ }
+ message += imported;
+ problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE).setMessage(message));
+
+ continue;
}
+
+ DependencyManagement importMgmt =
+ getCache(request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT);
+
+ if (importMgmt == null) {
+ if (workspaceResolver == null && modelResolver == null) {
+ throw new NullPointerException(String.format(
+ "request.workspaceModelResolver and request.modelResolver cannot be null"
+ + " (parent POM %s and POM %s)",
+ ModelProblemUtils.toId(groupId, artifactId, version),
+ ModelProblemUtils.toSourceHint(model)));
+ }
+
+ Model importModel = null;
+ if (workspaceResolver != null) {
+ try {
+ importModel = workspaceResolver.resolveEffectiveModel(groupId, artifactId, version);
+ } catch (UnresolvableModelException e) {
+ problems.add(new ModelProblemCollectorRequest(Severity.FATAL, Version.BASE)
+ .setMessage(e.getMessage().toString())
+ .setException(e));
+ continue;
+ }
+ }
+
+ // no workspace resolver or workspace resolver returned null (i.e. model not in workspace)
+ if (importModel == null) {
+ final ModelSource importSource;
+ try {
+ importSource = modelResolver.resolveModel(groupId, artifactId, version);
+ } catch (UnresolvableModelException e) {
+ StringBuilder buffer = new StringBuilder(256);
+ buffer.append("Non-resolvable import POM");
+ if (!containsCoordinates(e.getMessage(), groupId, artifactId, version)) {
+ buffer.append(' ').append(ModelProblemUtils.toId(groupId, artifactId, version));
+ }
+ buffer.append(": ").append(e.getMessage());
+
+ problems.add(new ModelProblemCollectorRequest(Severity.ERROR, Version.BASE)
+ .setMessage(buffer.toString())
+ .setLocation(dependency.getLocation(""))
+ .setException(e));
+ continue;
+ }
+
+ if (importRequest == null) {
+ importRequest = new DefaultModelBuildingRequest();
+ importRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
+ importRequest.setModelCache(request.getModelCache());
+ importRequest.setSystemProperties(request.getSystemProperties());
+ importRequest.setUserProperties(request.getUserProperties());
+ importRequest.setLocationTracking(request.isLocationTracking());
+ }
+
+ importRequest.setModelSource(importSource);
+ importRequest.setModelResolver(modelResolver.newCopy());
+
+ final ModelBuildingResult importResult;
+ try {
+ importResult = build(importRequest, importIds);
+ } catch (ModelBuildingException e) {
+ problems.addAll(e.getProblems());
+ continue;
+ }
+
+ problems.addAll(importResult.getProblems());
+
+ importModel = importResult.getEffectiveModel();
+ }
+
+ importMgmt = importModel.getDependencyManagement();
+
+ if (importMgmt == null) {
+ importMgmt = new DependencyManagement();
+ }
+
+ putCache(request.getModelCache(), groupId, artifactId, version, ModelCacheTag.IMPORT, importMgmt);
+ }
+
+ if (importMgmts == null) {
+ importMgmts = new ArrayList<>();
+ }
+
+ importMgmts.add(importMgmt);
}
importIds.remove(importing);
- model.update(
- dependencyManagementImporter.importManagement(model.getDelegate(), importMgmts, request, problems));
+ dependencyManagementImporter.importManagement(model, importMgmts, request, problems);
}
- private DependencyManagement loadDependencyManagement(
- Model model,
- ModelBuildingRequest request,
- DefaultModelProblemCollector problems,
- Dependency dependency,
- Collection importIds) {
- String groupId = dependency.getGroupId();
- String artifactId = dependency.getArtifactId();
- String version = dependency.getVersion();
-
- if (groupId == null || groupId.isEmpty()) {
- problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
- .setMessage("'dependencyManagement.dependencies.dependency.groupId' for "
- + dependency.getManagementKey() + " is missing.")
- .setLocation(dependency.getLocation("")));
- return null;
+ private void putCache(
+ ModelCache modelCache, String groupId, String artifactId, String version, ModelCacheTag tag, T data) {
+ if (modelCache != null) {
+ modelCache.put(groupId, artifactId, version, tag.getName(), tag.intoCache(data));
}
- if (artifactId == null || artifactId.isEmpty()) {
- problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
- .setMessage("'dependencyManagement.dependencies.dependency.artifactId' for "
- + dependency.getManagementKey() + " is missing.")
- .setLocation(dependency.getLocation("")));
- return null;
- }
- if (version == null || version.isEmpty()) {
- problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
- .setMessage("'dependencyManagement.dependencies.dependency.version' for "
- + dependency.getManagementKey() + " is missing.")
- .setLocation(dependency.getLocation("")));
- return null;
- }
-
- String imported = groupId + ':' + artifactId + ':' + version;
-
- if (importIds.contains(imported)) {
- StringBuilder message =
- new StringBuilder("The dependencies of type=pom and with scope=import form a cycle: ");
- for (String modelId : importIds) {
- message.append(modelId).append(" -> ");
- }
- message.append(imported);
- problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
- .setMessage(message.toString()));
-
- return null;
- }
-
- org.apache.maven.api.model.DependencyManagement importMgmt = cache(
- request.getModelCache(),
- groupId,
- artifactId,
- version,
- ModelCacheTag.IMPORT,
- () -> doLoadDependencyManagement(
- model, request, problems, dependency, groupId, artifactId, version, importIds));
-
- // [MNG-5600] Dependency management import should support exclusions.
- List exclusions = dependency.getDelegate().getExclusions();
- if (importMgmt != null && !exclusions.isEmpty()) {
- // Dependency excluded from import.
- List dependencies = importMgmt.getDependencies().stream()
- .filter(candidate -> exclusions.stream().noneMatch(exclusion -> match(exclusion, candidate)))
- .map(candidate -> addExclusions(candidate, exclusions))
- .collect(Collectors.toList());
- importMgmt = importMgmt.withDependencies(dependencies);
- }
-
- return importMgmt != null ? new DependencyManagement(importMgmt) : null;
}
- private static org.apache.maven.api.model.Dependency addExclusions(
- org.apache.maven.api.model.Dependency candidate, List exclusions) {
- return candidate.withExclusions(Stream.concat(candidate.getExclusions().stream(), exclusions.stream())
- .toList());
- }
-
- private boolean match(Exclusion exclusion, org.apache.maven.api.model.Dependency candidate) {
- return match(exclusion.getGroupId(), candidate.getGroupId())
- && match(exclusion.getArtifactId(), candidate.getArtifactId());
- }
-
- private boolean match(String match, String text) {
- return match.equals("*") || match.equals(text);
- }
-
- @SuppressWarnings("checkstyle:parameternumber")
- private org.apache.maven.api.model.DependencyManagement doLoadDependencyManagement(
- Model model,
- ModelBuildingRequest request,
- DefaultModelProblemCollector problems,
- Dependency dependency,
- String groupId,
- String artifactId,
- String version,
- Collection importIds) {
- DependencyManagement importMgmt;
- final WorkspaceModelResolver workspaceResolver = request.getWorkspaceModelResolver();
- final ModelResolver modelResolver = request.getModelResolver();
- if (workspaceResolver == null && modelResolver == null) {
- throw new NullPointerException(String.format(
- "request.workspaceModelResolver and request.modelResolver cannot be null (parent POM %s and POM %s)",
- ModelProblemUtils.toId(groupId, artifactId, version), ModelProblemUtils.toSourceHint(model)));
- }
-
- Model importModel = null;
- if (workspaceResolver != null) {
- try {
- importModel = workspaceResolver.resolveEffectiveModel(groupId, artifactId, version);
- } catch (UnresolvableModelException e) {
- problems.add(new ModelProblemCollectorRequest(Severity.FATAL, ModelProblem.Version.BASE)
- .setMessage(e.getMessage())
- .setException(e));
- return null;
+ private T getCache(
+ ModelCache modelCache, String groupId, String artifactId, String version, ModelCacheTag tag) {
+ if (modelCache != null) {
+ Object data = modelCache.get(groupId, artifactId, version, tag.getName());
+ if (data != null) {
+ return tag.fromCache(tag.getType().cast(data));
}
}
-
- // no workspace resolver or workspace resolver returned null (i.e. model not in workspace)
- if (importModel == null) {
- final ModelSource importSource;
- try {
- importSource = modelResolver.resolveModel(dependency);
- } catch (UnresolvableModelException e) {
- StringBuilder buffer = new StringBuilder(256);
- buffer.append("Non-resolvable import POM");
- if (!containsCoordinates(e.getMessage(), groupId, artifactId, version)) {
- buffer.append(' ').append(ModelProblemUtils.toId(groupId, artifactId, version));
- }
- buffer.append(": ").append(e.getMessage());
-
- problems.add(new ModelProblemCollectorRequest(Severity.ERROR, ModelProblem.Version.BASE)
- .setMessage(buffer.toString())
- .setLocation(dependency.getLocation(""))
- .setException(e));
- return null;
- }
-
- if (importSource instanceof FileModelSource && request.getRootDirectory() != null) {
- Path sourcePath = ((FileModelSource) importSource).getPath();
- if (sourcePath.startsWith(request.getRootDirectory())) {
- problems.add(new ModelProblemCollectorRequest(Severity.WARNING, ModelProblem.Version.BASE)
- .setMessage("BOM imports from within reactor should be avoided")
- .setLocation(dependency.getLocation("")));
- }
- }
-
- final ModelBuildingResult importResult;
- try {
- ModelBuildingRequest importRequest = new DefaultModelBuildingRequest();
- importRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
- importRequest.setModelCache(request.getModelCache());
- importRequest.setSystemProperties(request.getSystemProperties());
- importRequest.setUserProperties(request.getUserProperties());
- importRequest.setLocationTracking(request.isLocationTracking());
-
- importRequest.setModelSource(importSource);
- importRequest.setModelResolver(modelResolver.newCopy());
-
- importResult = build(importRequest, importIds);
- } catch (ModelBuildingException e) {
- problems.addAll(e.getProblems());
- return null;
- }
-
- problems.addAll(importResult.getProblems());
-
- importModel = importResult.getEffectiveModel();
- }
-
- importMgmt = importModel.getDependencyManagement();
-
- if (importMgmt == null) {
- importMgmt = new DependencyManagement();
- }
- return importMgmt.getDelegate();
- }
-
- private static T cache(
- ModelCache cache,
- String groupId,
- String artifactId,
- String version,
- ModelCacheTag tag,
- Callable supplier) {
- Supplier s = asSupplier(supplier);
- if (cache == null) {
- return s.get();
- } else {
- return cache.computeIfAbsent(groupId, artifactId, version, tag.getName(), s);
- }
- }
-
- private static T cache(ModelCache cache, Source source, ModelCacheTag tag, Callable supplier) {
- Supplier s = asSupplier(supplier);
- if (cache == null) {
- return s.get();
- } else {
- return cache.computeIfAbsent(source, tag.getName(), s);
- }
- }
-
- private static Supplier asSupplier(Callable supplier) {
- return () -> {
- try {
- return supplier.call();
- } catch (Exception e) {
- uncheckedThrow(e);
- return null;
- }
- };
- }
-
- static void uncheckedThrow(Throwable t) throws T {
- throw (T) t; // rely on vacuous cast
+ return null;
}
private void fireEvent(
Model model,
ModelBuildingRequest request,
ModelProblemCollector problems,
- ModelBuildingEventCatapult catapult) {
+ ModelBuildingEventCatapult catapult)
+ throws ModelBuildingException {
ModelBuildingListener listener = request.getModelBuildingListener();
if (listener != null) {
@@ -2021,8 +1325,4 @@ public class DefaultModelBuilder implements ModelBuilder {
throw new IllegalStateException();
}
}
-
- ModelProcessor getModelProcessor() {
- return modelProcessor;
- }
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilderFactory.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilderFactory.java
index 92db3fdc6b..d21c86841d 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilderFactory.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilderFactory.java
@@ -18,13 +18,6 @@
*/
package org.apache.maven.model.building;
-import java.util.Arrays;
-
-import org.apache.maven.api.Version;
-import org.apache.maven.api.VersionConstraint;
-import org.apache.maven.api.VersionRange;
-import org.apache.maven.api.services.model.ModelVersionParser;
-import org.apache.maven.api.spi.ModelParser;
import org.apache.maven.model.Model;
import org.apache.maven.model.composition.DefaultDependencyManagementImporter;
import org.apache.maven.model.composition.DependencyManagementImporter;
@@ -69,165 +62,27 @@ import org.apache.maven.model.profile.activation.JdkVersionProfileActivator;
import org.apache.maven.model.profile.activation.OperatingSystemProfileActivator;
import org.apache.maven.model.profile.activation.ProfileActivator;
import org.apache.maven.model.profile.activation.PropertyProfileActivator;
-import org.apache.maven.model.root.DefaultRootLocator;
-import org.apache.maven.model.root.RootLocator;
import org.apache.maven.model.superpom.DefaultSuperPomProvider;
import org.apache.maven.model.superpom.SuperPomProvider;
import org.apache.maven.model.validation.DefaultModelValidator;
import org.apache.maven.model.validation.ModelValidator;
-import static java.util.Objects.requireNonNull;
-
/**
* A factory to create model builder instances when no dependency injection is available. Note: This class is
- * only meant as a utility for developers that want to employ the model builder outside the Maven build system, Maven
+ * only meant as a utility for developers that want to employ the model builder outside of the Maven build system, Maven
* plugins should always acquire model builder instances via dependency injection. Developers might want to subclass
- * this factory to provide custom implementations for some of the components used by the model builder, or use the
- * builder API to inject custom instances.
+ * this factory to provide custom implementations for some of the components used by the model builder.
*
* @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
*/
@Deprecated(since = "4.0.0")
public class DefaultModelBuilderFactory {
- private ModelProcessor modelProcessor;
- private ModelValidator modelValidator;
- private ModelNormalizer modelNormalizer;
- private ModelInterpolator modelInterpolator;
- private ModelPathTranslator modelPathTranslator;
- private ModelUrlNormalizer modelUrlNormalizer;
- private SuperPomProvider superPomProvider;
- private InheritanceAssembler inheritanceAssembler;
- private ProfileSelector profileSelector;
- private ProfileInjector profileInjector;
- private PluginManagementInjector pluginManagementInjector;
- private DependencyManagementInjector dependencyManagementInjector;
- private DependencyManagementImporter dependencyManagementImporter;
- private LifecycleBindingsInjector lifecycleBindingsInjector;
- private PluginConfigurationExpander pluginConfigurationExpander;
- private ReportConfigurationExpander reportConfigurationExpander;
- private ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator;
- private ModelVersionProcessor versionProcessor;
- private ModelSourceTransformer transformer;
- private ModelVersionParser versionParser;
-
- public DefaultModelBuilderFactory setModelProcessor(ModelProcessor modelProcessor) {
- this.modelProcessor = modelProcessor;
- return this;
- }
-
- public DefaultModelBuilderFactory setModelValidator(ModelValidator modelValidator) {
- this.modelValidator = modelValidator;
- return this;
- }
-
- public DefaultModelBuilderFactory setModelNormalizer(ModelNormalizer modelNormalizer) {
- this.modelNormalizer = modelNormalizer;
- return this;
- }
-
- public DefaultModelBuilderFactory setModelInterpolator(ModelInterpolator modelInterpolator) {
- this.modelInterpolator = modelInterpolator;
- return this;
- }
-
- public DefaultModelBuilderFactory setModelPathTranslator(ModelPathTranslator modelPathTranslator) {
- this.modelPathTranslator = modelPathTranslator;
- return this;
- }
-
- public DefaultModelBuilderFactory setModelUrlNormalizer(ModelUrlNormalizer modelUrlNormalizer) {
- this.modelUrlNormalizer = modelUrlNormalizer;
- return this;
- }
-
- public DefaultModelBuilderFactory setSuperPomProvider(SuperPomProvider superPomProvider) {
- this.superPomProvider = superPomProvider;
- return this;
- }
-
- public DefaultModelBuilderFactory setInheritanceAssembler(InheritanceAssembler inheritanceAssembler) {
- this.inheritanceAssembler = inheritanceAssembler;
- return this;
- }
-
- public DefaultModelBuilderFactory setProfileSelector(ProfileSelector profileSelector) {
- this.profileSelector = profileSelector;
- return this;
- }
-
- public DefaultModelBuilderFactory setProfileInjector(ProfileInjector profileInjector) {
- this.profileInjector = profileInjector;
- return this;
- }
-
- public DefaultModelBuilderFactory setPluginManagementInjector(PluginManagementInjector pluginManagementInjector) {
- this.pluginManagementInjector = pluginManagementInjector;
- return this;
- }
-
- public DefaultModelBuilderFactory setDependencyManagementInjector(
- DependencyManagementInjector dependencyManagementInjector) {
- this.dependencyManagementInjector = dependencyManagementInjector;
- return this;
- }
-
- public DefaultModelBuilderFactory setDependencyManagementImporter(
- DependencyManagementImporter dependencyManagementImporter) {
- this.dependencyManagementImporter = dependencyManagementImporter;
- return this;
- }
-
- public DefaultModelBuilderFactory setLifecycleBindingsInjector(
- LifecycleBindingsInjector lifecycleBindingsInjector) {
- this.lifecycleBindingsInjector = lifecycleBindingsInjector;
- return this;
- }
-
- public DefaultModelBuilderFactory setPluginConfigurationExpander(
- PluginConfigurationExpander pluginConfigurationExpander) {
- this.pluginConfigurationExpander = pluginConfigurationExpander;
- return this;
- }
-
- public DefaultModelBuilderFactory setReportConfigurationExpander(
- ReportConfigurationExpander reportConfigurationExpander) {
- this.reportConfigurationExpander = reportConfigurationExpander;
- return this;
- }
-
- @Deprecated
- public DefaultModelBuilderFactory setReportingConverter(ReportingConverter reportingConverter) {
- return this;
- }
-
- public DefaultModelBuilderFactory setProfileActivationFilePathInterpolator(
- ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator) {
- this.profileActivationFilePathInterpolator = profileActivationFilePathInterpolator;
- return this;
- }
-
- public DefaultModelBuilderFactory setVersionProcessor(ModelVersionProcessor versionProcessor) {
- this.versionProcessor = versionProcessor;
- return this;
- }
-
- public DefaultModelBuilderFactory setTransformer(ModelSourceTransformer transformer) {
- this.transformer = transformer;
- return this;
- }
-
- public DefaultModelBuilderFactory setModelVersionParser(ModelVersionParser versionParser) {
- this.versionParser = versionParser;
- return this;
- }
-
protected ModelProcessor newModelProcessor() {
- return new DefaultModelProcessor(Arrays.asList(newModelParsers()), newModelLocator(), newModelReader());
- }
-
- protected ModelParser[] newModelParsers() {
- return new ModelParser[0];
+ DefaultModelProcessor processor = new DefaultModelProcessor();
+ processor.setModelLocator(newModelLocator());
+ processor.setModelReader(newModelReader());
+ return processor;
}
protected ModelLocator newModelLocator() {
@@ -235,11 +90,17 @@ public class DefaultModelBuilderFactory {
}
protected ModelReader newModelReader() {
- return new DefaultModelReader(newModelSourceTransformer());
+ return new DefaultModelReader();
}
protected ProfileSelector newProfileSelector() {
- return new DefaultProfileSelector(Arrays.asList(newProfileActivators()));
+ DefaultProfileSelector profileSelector = new DefaultProfileSelector();
+
+ for (ProfileActivator activator : newProfileActivators()) {
+ profileSelector.addProfileActivator(activator);
+ }
+
+ return profileSelector;
}
protected ProfileActivator[] newProfileActivators() {
@@ -247,12 +108,13 @@ public class DefaultModelBuilderFactory {
new JdkVersionProfileActivator(),
new OperatingSystemProfileActivator(),
new PropertyProfileActivator(),
- new FileProfileActivator(newProfileActivationFilePathInterpolator())
+ new FileProfileActivator()
+ .setProfileActivationFilePathInterpolator(newProfileActivationFilePathInterpolator())
};
}
protected ProfileActivationFilePathInterpolator newProfileActivationFilePathInterpolator() {
- return new ProfileActivationFilePathInterpolator(newPathTranslator(), newRootLocator());
+ return new ProfileActivationFilePathInterpolator().setPathTranslator(newPathTranslator());
}
protected UrlNormalizer newUrlNormalizer() {
@@ -263,15 +125,13 @@ public class DefaultModelBuilderFactory {
return new DefaultPathTranslator();
}
- protected RootLocator newRootLocator() {
- return new DefaultRootLocator();
- }
-
protected ModelInterpolator newModelInterpolator() {
UrlNormalizer normalizer = newUrlNormalizer();
PathTranslator pathTranslator = newPathTranslator();
- RootLocator rootLocator = newRootLocator();
- return new StringVisitorModelInterpolator(pathTranslator, normalizer, rootLocator);
+ return new StringVisitorModelInterpolator()
+ .setPathTranslator(pathTranslator)
+ .setUrlNormalizer(normalizer)
+ .setVersionPropertiesProcessor(newModelVersionPropertiesProcessor());
}
protected ModelVersionProcessor newModelVersionPropertiesProcessor() {
@@ -279,8 +139,7 @@ public class DefaultModelBuilderFactory {
}
protected ModelValidator newModelValidator() {
- ModelVersionProcessor processor = newModelVersionPropertiesProcessor();
- return new DefaultModelValidator(processor);
+ return new DefaultModelValidator(newModelVersionPropertiesProcessor());
}
protected ModelNormalizer newModelNormalizer() {
@@ -288,11 +147,11 @@ public class DefaultModelBuilderFactory {
}
protected ModelPathTranslator newModelPathTranslator() {
- return new DefaultModelPathTranslator(newPathTranslator());
+ return new DefaultModelPathTranslator().setPathTranslator(newPathTranslator());
}
protected ModelUrlNormalizer newModelUrlNormalizer() {
- return new DefaultModelUrlNormalizer(newUrlNormalizer());
+ return new DefaultModelUrlNormalizer().setUrlNormalizer(newUrlNormalizer());
}
protected InheritanceAssembler newInheritanceAssembler() {
@@ -304,7 +163,7 @@ public class DefaultModelBuilderFactory {
}
protected SuperPomProvider newSuperPomProvider() {
- return new DefaultSuperPomProvider(newModelProcessor());
+ return new DefaultSuperPomProvider().setModelProcessor(newModelProcessor());
}
protected DependencyManagementImporter newDependencyManagementImporter() {
@@ -331,82 +190,38 @@ public class DefaultModelBuilderFactory {
return new DefaultReportConfigurationExpander();
}
- @Deprecated
protected ReportingConverter newReportingConverter() {
return new DefaultReportingConverter();
}
- private ModelSourceTransformer newModelSourceTransformer() {
- return new BuildModelSourceTransformer();
- }
-
- private ModelVersionParser newModelVersionParser() {
- // This is a limited parser that does not support ranges and compares versions as strings
- // in real-life this parser should not be used, but replaced with a proper one
- return new ModelVersionParser() {
- @Override
- public Version parseVersion(String version) {
- requireNonNull(version, "version");
- return new Version() {
- @Override
- public String asString() {
- return version;
- }
-
- @Override
- public int compareTo(Version o) {
- return version.compareTo(o.asString());
- }
- };
- }
-
- @Override
- public VersionRange parseVersionRange(String range) {
- throw new IllegalArgumentException("ranges not supported by this parser");
- }
-
- @Override
- public VersionConstraint parseVersionConstraint(String constraint) {
- throw new IllegalArgumentException("constraint not supported by this parser");
- }
-
- @Override
- public boolean isSnapshot(String version) {
- requireNonNull(version, "version");
- return version.endsWith("SNAPSHOT");
- }
- };
- }
-
/**
* Creates a new model builder instance.
*
* @return The new model builder instance, never {@code null}.
*/
public DefaultModelBuilder newInstance() {
- return new DefaultModelBuilder(
- modelProcessor != null ? modelProcessor : newModelProcessor(),
- modelValidator != null ? modelValidator : newModelValidator(),
- modelNormalizer != null ? modelNormalizer : newModelNormalizer(),
- modelInterpolator != null ? modelInterpolator : newModelInterpolator(),
- modelPathTranslator != null ? modelPathTranslator : newModelPathTranslator(),
- modelUrlNormalizer != null ? modelUrlNormalizer : newModelUrlNormalizer(),
- superPomProvider != null ? superPomProvider : newSuperPomProvider(),
- inheritanceAssembler != null ? inheritanceAssembler : newInheritanceAssembler(),
- profileSelector != null ? profileSelector : newProfileSelector(),
- profileInjector != null ? profileInjector : newProfileInjector(),
- pluginManagementInjector != null ? pluginManagementInjector : newPluginManagementInjector(),
- dependencyManagementInjector != null ? dependencyManagementInjector : newDependencyManagementInjector(),
- dependencyManagementImporter != null ? dependencyManagementImporter : newDependencyManagementImporter(),
- lifecycleBindingsInjector != null ? lifecycleBindingsInjector : newLifecycleBindingsInjector(),
- pluginConfigurationExpander != null ? pluginConfigurationExpander : newPluginConfigurationExpander(),
- reportConfigurationExpander != null ? reportConfigurationExpander : newReportConfigurationExpander(),
- profileActivationFilePathInterpolator != null
- ? profileActivationFilePathInterpolator
- : newProfileActivationFilePathInterpolator(),
- versionProcessor != null ? versionProcessor : newModelVersionPropertiesProcessor(),
- transformer != null ? transformer : newModelSourceTransformer(),
- versionParser != null ? versionParser : newModelVersionParser());
+ DefaultModelBuilder modelBuilder = new DefaultModelBuilder();
+
+ modelBuilder.setModelProcessor(newModelProcessor());
+ modelBuilder.setModelValidator(newModelValidator());
+ modelBuilder.setModelNormalizer(newModelNormalizer());
+ modelBuilder.setModelPathTranslator(newModelPathTranslator());
+ modelBuilder.setModelUrlNormalizer(newModelUrlNormalizer());
+ modelBuilder.setModelInterpolator(newModelInterpolator());
+ modelBuilder.setInheritanceAssembler(newInheritanceAssembler());
+ modelBuilder.setProfileInjector(newProfileInjector());
+ modelBuilder.setProfileSelector(newProfileSelector());
+ modelBuilder.setSuperPomProvider(newSuperPomProvider());
+ modelBuilder.setDependencyManagementImporter(newDependencyManagementImporter());
+ modelBuilder.setDependencyManagementInjector(newDependencyManagementInjector());
+ modelBuilder.setLifecycleBindingsInjector(newLifecycleBindingsInjector());
+ modelBuilder.setPluginManagementInjector(newPluginManagementInjector());
+ modelBuilder.setPluginConfigurationExpander(newPluginConfigurationExpander());
+ modelBuilder.setReportConfigurationExpander(newReportConfigurationExpander());
+ modelBuilder.setReportingConverter(newReportingConverter());
+ modelBuilder.setProfileActivationFilePathInterpolator(newProfileActivationFilePathInterpolator());
+
+ return modelBuilder;
}
private static class StubLifecycleBindingsInjector implements LifecycleBindingsInjector {
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingEvent.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingEvent.java
index c78b798b99..95eef4773b 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingEvent.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingEvent.java
@@ -28,7 +28,7 @@ import org.apache.maven.model.Model;
@Deprecated(since = "4.0.0")
class DefaultModelBuildingEvent implements ModelBuildingEvent {
- private Model model;
+ private final Model model;
private final ModelBuildingRequest request;
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
index c4e562f7e5..22b1c96f72 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingRequest.java
@@ -19,7 +19,6 @@
package org.apache.maven.model.building;
import java.io.File;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -37,9 +36,10 @@ import org.apache.maven.model.resolution.WorkspaceModelResolver;
*/
@Deprecated(since = "4.0.0")
public class DefaultModelBuildingRequest implements ModelBuildingRequest {
- private Model fileModel;
- private Path pomPath;
+ private Model rawModel;
+
+ private File pomFile;
private ModelSource modelSource;
@@ -71,10 +71,6 @@ public class DefaultModelBuildingRequest implements ModelBuildingRequest {
private WorkspaceModelResolver workspaceResolver;
- private TransformerContextBuilder contextBuilder;
-
- private Path rootDirectory;
-
/**
* Creates an empty request.
*/
@@ -86,7 +82,7 @@ public class DefaultModelBuildingRequest implements ModelBuildingRequest {
* @param request The request to copy, must not be {@code null}.
*/
public DefaultModelBuildingRequest(ModelBuildingRequest request) {
- setPomPath(request.getPomPath());
+ setPomFile(request.getPomFile());
setModelSource(request.getModelSource());
setValidationLevel(request.getValidationLevel());
setProcessPlugins(request.isProcessPlugins());
@@ -101,39 +97,24 @@ public class DefaultModelBuildingRequest implements ModelBuildingRequest {
setModelResolver(request.getModelResolver());
setModelBuildingListener(request.getModelBuildingListener());
setModelCache(request.getModelCache());
- setWorkspaceModelResolver(request.getWorkspaceModelResolver());
- setTransformerContextBuilder(request.getTransformerContextBuilder());
- setRootDirectory(request.getRootDirectory());
}
- @Deprecated
@Override
public File getPomFile() {
- return pomPath != null ? pomPath.toFile() : null;
+ return pomFile;
}
- @Override
- public Path getPomPath() {
- return pomPath;
- }
-
- @Deprecated
@Override
public DefaultModelBuildingRequest setPomFile(File pomFile) {
- this.pomPath = (pomFile != null) ? pomFile.toPath().toAbsolutePath() : null;
- return this;
- }
+ this.pomFile = (pomFile != null) ? pomFile.getAbsoluteFile() : null;
- @Override
- public DefaultModelBuildingRequest setPomPath(Path pomPath) {
- this.pomPath = (pomPath != null) ? pomPath.toAbsolutePath() : null;
return this;
}
@Override
public synchronized ModelSource getModelSource() {
- if (modelSource == null && pomPath != null) {
- modelSource = new FileModelSource(pomPath);
+ if (modelSource == null && pomFile != null) {
+ modelSource = new FileModelSource(pomFile);
}
return modelSource;
}
@@ -266,8 +247,9 @@ public class DefaultModelBuildingRequest implements ModelBuildingRequest {
public DefaultModelBuildingRequest setSystemProperties(Properties systemProperties) {
if (systemProperties != null) {
this.systemProperties = new Properties();
- // avoid concurrent modification if someone else sets/removes an unrelated system property
- synchronized (systemProperties) {
+ synchronized (
+ systemProperties) { // avoid concurrentmodification if someone else sets/removes an unrelated system
+ // property
this.systemProperties.putAll(systemProperties);
}
} else {
@@ -346,24 +328,14 @@ public class DefaultModelBuildingRequest implements ModelBuildingRequest {
return this;
}
- @Override
- public Model getFileModel() {
- return fileModel;
- }
-
- @Override
- public ModelBuildingRequest setFileModel(Model fileModel) {
- this.fileModel = fileModel;
- return this;
- }
-
@Override
public Model getRawModel() {
- return null;
+ return rawModel;
}
@Override
public ModelBuildingRequest setRawModel(Model rawModel) {
+ this.rawModel = rawModel;
return this;
}
@@ -377,26 +349,4 @@ public class DefaultModelBuildingRequest implements ModelBuildingRequest {
this.workspaceResolver = workspaceResolver;
return this;
}
-
- @Override
- public TransformerContextBuilder getTransformerContextBuilder() {
- return contextBuilder;
- }
-
- @Override
- public ModelBuildingRequest setTransformerContextBuilder(TransformerContextBuilder contextBuilder) {
- this.contextBuilder = contextBuilder;
- return this;
- }
-
- @Override
- public Path getRootDirectory() {
- return rootDirectory;
- }
-
- @Override
- public ModelBuildingRequest setRootDirectory(Path rootDirectory) {
- this.rootDirectory = rootDirectory;
- return this;
- }
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingResult.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingResult.java
index fbedb32a0e..c13a22b649 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingResult.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuildingResult.java
@@ -34,7 +34,6 @@ import org.apache.maven.model.Profile;
*/
@Deprecated(since = "4.0.0")
class DefaultModelBuildingResult implements ModelBuildingResult {
- private Model fileModel;
private Model effectiveModel;
@@ -56,31 +55,6 @@ class DefaultModelBuildingResult implements ModelBuildingResult {
problems = new ArrayList<>();
}
- DefaultModelBuildingResult(ModelBuildingResult result) {
- this();
- this.activeExternalProfiles.addAll(result.getActiveExternalProfiles());
- this.effectiveModel = result.getEffectiveModel();
- this.fileModel = result.getFileModel();
- this.problems.addAll(result.getProblems());
-
- for (String modelId : result.getModelIds()) {
- this.modelIds.add(modelId);
- this.rawModels.put(modelId, result.getRawModel(modelId));
- this.activePomProfiles.put(modelId, result.getActivePomProfiles(modelId));
- }
- }
-
- @Override
- public Model getFileModel() {
- return fileModel;
- }
-
- public DefaultModelBuildingResult setFileModel(Model fileModel) {
- this.fileModel = fileModel;
-
- return this;
- }
-
@Override
public Model getEffectiveModel() {
return effectiveModel;
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
index 01422f05fc..1f71d61c1e 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProblem.java
@@ -138,16 +138,16 @@ public class DefaultModelProblem implements ModelProblem {
@Override
public String getMessage() {
- String msg = null;
+ String msg;
- if (message != null && !message.isEmpty()) {
+ if (message != null && message.length() > 0) {
msg = message;
- } else if (exception != null) {
+ } else {
msg = exception.getMessage();
- }
- if (msg == null) {
- msg = "";
+ if (msg == null) {
+ msg = "";
+ }
}
return msg;
@@ -169,11 +169,7 @@ public class DefaultModelProblem implements ModelProblem {
buffer.append('[').append(getSeverity()).append("] ");
buffer.append(getMessage());
- String location = ModelProblemUtils.formatLocation(this, null);
- if (!location.isEmpty()) {
- buffer.append(" @ ");
- buffer.append(location);
- }
+ buffer.append(" @ ").append(ModelProblemUtils.formatLocation(this, null));
return buffer.toString();
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java
index 9012477557..5ffa16bce0 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java
@@ -26,18 +26,9 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import org.apache.maven.api.model.Model;
-import org.apache.maven.api.spi.ModelParser;
-import org.apache.maven.api.spi.ModelParserException;
-import org.apache.maven.model.io.ModelParseException;
+import org.apache.maven.model.Model;
import org.apache.maven.model.io.ModelReader;
import org.apache.maven.model.locator.ModelLocator;
import org.eclipse.sisu.Typed;
@@ -50,12 +41,12 @@ import org.eclipse.sisu.Typed;
* made this component available under all its interfaces then it could end up being injected
* into itself leading to a stack overflow.
*
- * A side effect of using @Typed is that it translates to explicit bindings in the container.
+ * A side-effect of using @Typed is that it translates to explicit bindings in the container.
* So instead of binding the component under a 'wildcard' key it is now bound with an explicit
* key. Since this is a default component this will be a plain binding of ModelProcessor to
* this implementation type, ie. no hint/name.
*
- * This leads to a second side effect in that any @Inject request for just ModelProcessor in
+ * This leads to a second side-effect in that any @Inject request for just ModelProcessor in
* the same injector is immediately matched to this explicit binding, which means extensions
* cannot override this binding. This is because the lookup is always short-circuited in this
* specific situation (plain @Inject request, and plain explicit binding for the same type.)
@@ -75,132 +66,39 @@ import org.eclipse.sisu.Typed;
@Deprecated(since = "4.0.0")
public class DefaultModelProcessor implements ModelProcessor {
- private final Collection modelParsers;
- private final ModelLocator modelLocator;
- private final ModelReader modelReader;
+ @Inject
+ private ModelLocator locator;
@Inject
- public DefaultModelProcessor(List modelParsers, ModelLocator modelLocator, ModelReader modelReader) {
- this.modelParsers = modelParsers;
- this.modelLocator = modelLocator;
- this.modelReader = modelReader;
+ private ModelReader reader;
+
+ public DefaultModelProcessor setModelLocator(ModelLocator locator) {
+ this.locator = locator;
+ return this;
+ }
+
+ public DefaultModelProcessor setModelReader(ModelReader reader) {
+ this.reader = reader;
+ return this;
}
- @Deprecated
@Override
public File locatePom(File projectDirectory) {
- return locatePom(projectDirectory.toPath()).toFile();
+ return locator.locatePom(projectDirectory);
}
@Override
- public Path locatePom(Path projectDirectory) {
- // Note that the ModelProcessor#locatePom never returns null
- // while the ModelParser#locatePom needs to return an existing path!
- Path pom = modelParsers.stream()
- .map(m -> m.locate(projectDirectory)
- .map(org.apache.maven.api.services.Source::getPath)
- .orElse(null))
- .filter(Objects::nonNull)
- .findFirst()
- .orElseGet(() -> modelLocator.locatePom(projectDirectory));
- if (!pom.equals(projectDirectory) && !pom.getParent().equals(projectDirectory)) {
- throw new IllegalArgumentException("The POM found does not belong to the given directory: " + pom);
- }
- return pom;
- }
-
- @Deprecated
- @Override
- public File locateExistingPom(File projectDirectory) {
- Path path = locateExistingPom(projectDirectory.toPath());
- return path != null ? path.toFile() : null;
+ public Model read(File input, Map options) throws IOException {
+ return reader.read(input, options);
}
@Override
- public Path locateExistingPom(Path projectDirectory) {
- // Note that the ModelProcessor#locatePom never returns null
- // while the ModelParser#locatePom needs to return an existing path!
- Path pom = modelParsers.stream()
- .map(m -> m.locate(projectDirectory)
- .map(org.apache.maven.api.services.Source::getPath)
- .orElse(null))
- .filter(Objects::nonNull)
- .findFirst()
- .orElseGet(() -> modelLocator.locateExistingPom(projectDirectory));
- if (pom != null && !pom.equals(projectDirectory) && !pom.getParent().equals(projectDirectory)) {
- throw new IllegalArgumentException("The POM found does not belong to the given directory: " + pom);
- }
- return pom;
- }
-
- protected org.apache.maven.api.model.Model read(
- Path pomFile, InputStream input, Reader reader, Map options) throws IOException {
- if (pomFile != null) {
- Path projectDirectory = pomFile.getParent();
- List exceptions = new ArrayList<>();
- for (ModelParser parser : modelParsers) {
- try {
- Optional model = parser.locateAndParse(projectDirectory, options);
- if (model.isPresent()) {
- return model.get().withPomFile(pomFile);
- }
- } catch (ModelParserException e) {
- exceptions.add(e);
- }
- }
- try {
- return readXmlModel(pomFile, null, null, options);
- } catch (IOException e) {
- exceptions.forEach(e::addSuppressed);
- throw e;
- }
- } else {
- return readXmlModel(pomFile, input, reader, options);
- }
- }
-
- private org.apache.maven.api.model.Model readXmlModel(
- Path pomFile, InputStream input, Reader reader, Map options) throws IOException {
- if (pomFile != null) {
- return modelReader.read(pomFile, options).getDelegate();
- } else if (input != null) {
- return modelReader.read(input, options).getDelegate();
- } else {
- return modelReader.read(reader, options).getDelegate();
- }
- }
-
- @Deprecated
- @Override
- public org.apache.maven.model.Model read(File file, Map options) throws IOException {
- Objects.requireNonNull(file, "file cannot be null");
- return read(file.toPath(), options);
+ public Model read(Reader input, Map options) throws IOException {
+ return reader.read(input, options);
}
@Override
- public org.apache.maven.model.Model read(Path path, Map options) throws IOException {
- Objects.requireNonNull(path, "path cannot be null");
- org.apache.maven.api.model.Model model = read(path, null, null, options);
- return new org.apache.maven.model.Model(model);
- }
-
- @Override
- public org.apache.maven.model.Model read(InputStream input, Map options) throws IOException {
- Objects.requireNonNull(input, "input cannot be null");
- try (InputStream in = input) {
- org.apache.maven.api.model.Model model = read(null, in, null, options);
- return new org.apache.maven.model.Model(model);
- } catch (ModelParserException e) {
- throw new ModelParseException("Unable to read model: " + e, e.getLineNumber(), e.getColumnNumber(), e);
- }
- }
-
- @Override
- public org.apache.maven.model.Model read(Reader reader, Map options) throws IOException {
- Objects.requireNonNull(reader, "reader cannot be null");
- try (Reader r = reader) {
- org.apache.maven.api.model.Model model = read(null, null, r, options);
- return new org.apache.maven.model.Model(model);
- }
+ public Model read(InputStream input, Map options) throws IOException {
+ return reader.read(input, options);
}
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java
deleted file mode 100644
index ecbc09303d..0000000000
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContext.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.model.building;
-
-import java.io.File;
-import java.nio.file.Path;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Supplier;
-
-import org.apache.maven.model.Model;
-import org.apache.maven.model.locator.ModelLocator;
-
-/**
- *
- * @since 4.0.0
- * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
- */
-@Deprecated(since = "4.0.0")
-class DefaultTransformerContext implements TransformerContext {
- final ModelLocator modelLocator;
-
- final Map userProperties = new ConcurrentHashMap<>();
-
- final Map modelByPath = new ConcurrentHashMap<>();
-
- final Map modelByGA = new ConcurrentHashMap<>();
-
- public static class Holder {
- private volatile boolean set;
- private volatile Model model;
-
- Holder() {}
-
- Holder(Model model) {
- this.model = Objects.requireNonNull(model);
- this.set = true;
- }
-
- public static Model deref(Holder holder) {
- return holder != null ? holder.get() : null;
- }
-
- public Model get() {
- if (!set) {
- synchronized (this) {
- if (!set) {
- try {
- this.wait();
- } catch (InterruptedException e) {
- // Ignore
- }
- }
- }
- }
- return model;
- }
-
- public Model computeIfAbsent(Supplier supplier) {
- if (!set) {
- synchronized (this) {
- if (!set) {
- this.set = true;
- this.model = supplier.get();
- this.notifyAll();
- }
- }
- }
- return model;
- }
- }
-
- DefaultTransformerContext(ModelLocator modelLocator) {
- this.modelLocator = modelLocator;
- }
-
- @Override
- public String getUserProperty(String key) {
- return userProperties.get(key);
- }
-
- @Override
- public Model getRawModel(Path from, Path p) {
- return Holder.deref(modelByPath.get(p));
- }
-
- @Override
- public Model getRawModel(Path from, String groupId, String artifactId) {
- return Holder.deref(modelByGA.get(new GAKey(groupId, artifactId)));
- }
-
- @Override
- public Path locate(Path path) {
- File file = modelLocator.locateExistingPom(path.toFile());
- return file != null ? file.toPath() : null;
- }
-
- static class GAKey {
- private final String groupId;
- private final String artifactId;
- private final int hashCode;
-
- GAKey(String groupId, String artifactId) {
- this.groupId = groupId;
- this.artifactId = artifactId;
- this.hashCode = Objects.hash(groupId, artifactId);
- }
-
- @Override
- public int hashCode() {
- return hashCode;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof GAKey)) {
- return false;
- }
-
- GAKey other = (GAKey) obj;
- return Objects.equals(artifactId, other.artifactId) && Objects.equals(groupId, other.groupId);
- }
- }
-}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContextBuilder.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContextBuilder.java
deleted file mode 100644
index e0f22ef2c5..0000000000
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultTransformerContextBuilder.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.model.building;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.maven.model.Model;
-import org.apache.maven.model.building.DefaultTransformerContext.GAKey;
-import org.apache.maven.model.building.DefaultTransformerContext.Holder;
-
-/**
- * Builds up the transformer context.
- * After the buildplan is ready, the build()-method returns the immutable context useful during distribution.
- * This is an inner class, as it must be able to call readRawModel()
- *
- * @since 4.0.0
- * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
- */
-@Deprecated(since = "4.0.0")
-class DefaultTransformerContextBuilder implements TransformerContextBuilder {
- private final Graph dag = new Graph();
- private final DefaultModelBuilder defaultModelBuilder;
- private final DefaultTransformerContext context;
-
- private final Map> mappedSources = new ConcurrentHashMap<>(64);
-
- private volatile boolean fullReactorLoaded;
-
- DefaultTransformerContextBuilder(DefaultModelBuilder defaultModelBuilder) {
- this.defaultModelBuilder = defaultModelBuilder;
- this.context = new DefaultTransformerContext(defaultModelBuilder.getModelProcessor());
- }
-
- /**
- * If an interface could be extracted, DefaultModelProblemCollector should be ModelProblemCollectorExt
- */
- @Override
- public TransformerContext initialize(ModelBuildingRequest request, ModelProblemCollector collector) {
- // We must assume the TransformerContext was created using this.newTransformerContextBuilder()
- DefaultModelProblemCollector problems = (DefaultModelProblemCollector) collector;
- return new TransformerContext() {
-
- @Override
- public Path locate(Path path) {
- return context.locate(path);
- }
-
- @Override
- public String getUserProperty(String key) {
- return context.userProperties.computeIfAbsent(
- key, k -> request.getUserProperties().getProperty(key));
- }
-
- @Override
- public Model getRawModel(Path from, String gId, String aId) {
- Model model = findRawModel(from, gId, aId);
- if (model != null) {
- context.modelByGA.put(new GAKey(gId, aId), new Holder(model));
- context.modelByPath.put(model.getPomPath(), new Holder(model));
- }
- return model;
- }
-
- @Override
- public Model getRawModel(Path from, Path path) {
- Model model = findRawModel(from, path);
- if (model != null) {
- String groupId = defaultModelBuilder.getGroupId(model);
- context.modelByGA.put(
- new DefaultTransformerContext.GAKey(groupId, model.getArtifactId()), new Holder(model));
- context.modelByPath.put(path, new Holder(model));
- }
- return model;
- }
-
- private Model findRawModel(Path from, String groupId, String artifactId) {
- FileModelSource source = getSource(groupId, artifactId);
- if (source == null) {
- // we need to check the whole reactor in case it's a dependency
- loadFullReactor();
- source = getSource(groupId, artifactId);
- }
- if (source != null) {
- if (!addEdge(from, source.getPath(), problems)) {
- return null;
- }
- try {
- ModelBuildingRequest gaBuildingRequest =
- new DefaultModelBuildingRequest(request).setModelSource(source);
- return defaultModelBuilder.readRawModel(gaBuildingRequest, problems);
- } catch (ModelBuildingException e) {
- // gathered with problem collector
- }
- }
- return null;
- }
-
- private void loadFullReactor() {
- if (!fullReactorLoaded) {
- synchronized (DefaultTransformerContextBuilder.this) {
- if (!fullReactorLoaded) {
- doLoadFullReactor();
- fullReactorLoaded = true;
- }
- }
- }
- }
-
- private void doLoadFullReactor() {
- Path rootDirectory = request.getRootDirectory();
- if (rootDirectory == null) {
- return;
- }
- List toLoad = new ArrayList<>();
- Path root = defaultModelBuilder.getModelProcessor().locateExistingPom(rootDirectory);
- toLoad.add(root);
- while (!toLoad.isEmpty()) {
- Path pom = toLoad.remove(0);
- try {
- ModelBuildingRequest gaBuildingRequest =
- new DefaultModelBuildingRequest(request).setModelSource(new FileModelSource(pom));
- Model rawModel = defaultModelBuilder.readFileModel(gaBuildingRequest, problems);
- for (String module : rawModel.getModules()) {
- Path moduleFile = defaultModelBuilder
- .getModelProcessor()
- .locateExistingPom(pom.getParent().resolve(module));
- if (moduleFile != null) {
- toLoad.add(moduleFile);
- }
- }
- } catch (ModelBuildingException e) {
- // gathered with problem collector
- }
- }
- }
-
- private Model findRawModel(Path from, Path p) {
- if (!Files.isRegularFile(p)) {
- throw new IllegalArgumentException("Not a regular file: " + p);
- }
-
- if (!addEdge(from, p, problems)) {
- return null;
- }
-
- DefaultModelBuildingRequest req =
- new DefaultModelBuildingRequest(request).setPomPath(p).setModelSource(new FileModelSource(p));
-
- try {
- return defaultModelBuilder.readRawModel(req, problems);
- } catch (ModelBuildingException e) {
- // gathered with problem collector
- }
- return null;
- }
- };
- }
-
- private boolean addEdge(Path from, Path p, DefaultModelProblemCollector problems) {
- try {
- dag.addEdge(from.toString(), p.toString());
- return true;
- } catch (Graph.CycleDetectedException e) {
- problems.add(new DefaultModelProblem(
- "Cycle detected between models at " + from + " and " + p,
- ModelProblem.Severity.FATAL,
- null,
- null,
- 0,
- 0,
- null,
- e));
- return false;
- }
- }
-
- @Override
- public TransformerContext build() {
- return context;
- }
-
- public FileModelSource getSource(String groupId, String artifactId) {
- Set sources = mappedSources.get(groupId != null ? groupId + ":" + artifactId : artifactId);
- if (sources == null) {
- return null;
- }
- return sources.stream()
- .reduce((a, b) -> {
- throw new IllegalStateException(String.format(
- "No unique Source for %s:%s: %s and %s",
- groupId, artifactId, a.getLocation(), b.getLocation()));
- })
- .orElse(null);
- }
-
- public void putSource(String groupId, String artifactId, FileModelSource source) {
- mappedSources
- .computeIfAbsent(groupId + ":" + artifactId, k -> new HashSet<>())
- .add(source);
- if (groupId != null) {
- mappedSources.computeIfAbsent(artifactId, k -> new HashSet<>()).add(source);
- }
- }
-}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/FileModelSource.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/FileModelSource.java
index 7bc8135e41..2b8f03acfb 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/FileModelSource.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/FileModelSource.java
@@ -20,10 +20,8 @@ package org.apache.maven.model.building;
import java.io.File;
import java.net.URI;
-import java.nio.file.Path;
import org.apache.maven.building.FileSource;
-import org.apache.maven.model.locator.ModelLocator;
/**
* Wraps an ordinary {@link File} as a model source.
@@ -31,29 +29,17 @@ import org.apache.maven.model.locator.ModelLocator;
* @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
*/
@Deprecated(since = "4.0.0")
-public class FileModelSource extends FileSource implements ModelSource3 {
+public class FileModelSource extends FileSource implements ModelSource2 {
/**
* Creates a new model source backed by the specified file.
*
* @param pomFile The POM file, must not be {@code null}.
- * @deprecated Use {@link #FileModelSource(Path)} instead.
*/
- @Deprecated
public FileModelSource(File pomFile) {
super(pomFile);
}
- /**
- * Creates a new model source backed by the specified file.
- *
- * @param pomPath The POM file, must not be {@code null}.
- * @since 4.0.0
- */
- public FileModelSource(Path pomPath) {
- super(pomPath);
- }
-
/**
*
* @return the file of this source
@@ -66,15 +52,18 @@ public class FileModelSource extends FileSource implements ModelSource3 {
}
@Override
- public ModelSource3 getRelatedSource(ModelLocator locator, String relPath) {
+ public ModelSource2 getRelatedSource(String relPath) {
relPath = relPath.replace('\\', File.separatorChar).replace('/', File.separatorChar);
- Path path = getPath().getParent().resolve(relPath);
+ File relatedPom = new File(getFile().getParentFile(), relPath);
- Path relatedPom = locator.locateExistingPom(path);
+ if (relatedPom.isDirectory()) {
+ // TODO figure out how to reuse ModelLocator.locatePom(File) here
+ relatedPom = new File(relatedPom, "pom.xml");
+ }
- if (relatedPom != null) {
- return new FileModelSource(relatedPom.normalize());
+ if (relatedPom.isFile() && relatedPom.canRead()) {
+ return new FileModelSource(new File(relatedPom.toURI().normalize()));
}
return null;
@@ -82,7 +71,7 @@ public class FileModelSource extends FileSource implements ModelSource3 {
@Override
public URI getLocationURI() {
- return getPath().toUri();
+ return getFile().toURI();
}
@Override
@@ -91,19 +80,15 @@ public class FileModelSource extends FileSource implements ModelSource3 {
return true;
}
- if (obj == null) {
- return false;
- }
-
- if (!FileModelSource.class.equals(obj.getClass())) {
+ if (!(obj instanceof FileModelSource)) {
return false;
}
FileModelSource other = (FileModelSource) obj;
- return getPath().equals(other.getPath());
+ return getFile().equals(other.getFile());
}
@Override
public int hashCode() {
- return getPath().hashCode();
+ return getFile().hashCode();
}
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java
index 6eb9b9d2f1..40480ce2f5 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/FilterModelBuildingRequest.java
@@ -19,7 +19,6 @@
package org.apache.maven.model.building;
import java.io.File;
-import java.nio.file.Path;
import java.util.Date;
import java.util.List;
import java.util.Properties;
@@ -44,27 +43,15 @@ class FilterModelBuildingRequest implements ModelBuildingRequest {
this.request = request;
}
- @Deprecated
@Override
public File getPomFile() {
return request.getPomFile();
}
@Override
- public Path getPomPath() {
- return request.getPomPath();
- }
-
- @Deprecated
- @Override
- public ModelBuildingRequest setPomFile(File pomFile) {
+ public FilterModelBuildingRequest setPomFile(File pomFile) {
request.setPomFile(pomFile);
- return this;
- }
- @Override
- public FilterModelBuildingRequest setPomPath(Path pomPath) {
- request.setPomPath(pomPath);
return this;
}
@@ -236,17 +223,6 @@ class FilterModelBuildingRequest implements ModelBuildingRequest {
return this;
}
- @Override
- public Model getFileModel() {
- return request.getFileModel();
- }
-
- @Override
- public ModelBuildingRequest setFileModel(Model fileModel) {
- request.setFileModel(fileModel);
- return this;
- }
-
@Override
public Model getRawModel() {
return request.getRawModel();
@@ -268,26 +244,4 @@ class FilterModelBuildingRequest implements ModelBuildingRequest {
request.setWorkspaceModelResolver(workspaceResolver);
return this;
}
-
- @Override
- public TransformerContextBuilder getTransformerContextBuilder() {
- return request.getTransformerContextBuilder();
- }
-
- @Override
- public ModelBuildingRequest setTransformerContextBuilder(TransformerContextBuilder contextBuilder) {
- request.setTransformerContextBuilder(contextBuilder);
- return this;
- }
-
- @Override
- public Path getRootDirectory() {
- return request.getRootDirectory();
- }
-
- @Override
- public ModelBuildingRequest setRootDirectory(Path rootDirectory) {
- request.setRootDirectory(rootDirectory);
- return this;
- }
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuilder.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuilder.java
index 2217517689..f2c75b305a 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuilder.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuilder.java
@@ -19,7 +19,6 @@
package org.apache.maven.model.building;
import java.io.File;
-import java.nio.file.Path;
import org.apache.maven.model.Model;
@@ -55,31 +54,6 @@ public interface ModelBuilder {
/**
* Performs only the part of {@link ModelBuilder#build(ModelBuildingRequest)} that loads the raw model
- *
- * @deprecated Use {@link #buildRawModel(Path, int, boolean)} instead.
*/
- @Deprecated
Result extends Model> buildRawModel(File pomFile, int validationLevel, boolean locationTracking);
-
- /**
- * Performs only the part of {@link ModelBuilder#build(ModelBuildingRequest)} that loads the raw model
- *
- * @since 4.0.0
- */
- Result extends Model> buildRawModel(Path pomFile, int validationLevel, boolean locationTracking);
-
- /**
- * @deprecated Use {@link #buildRawModel(Path, int, boolean, TransformerContext)} instead.
- */
- @Deprecated
- Result extends Model> buildRawModel(
- File pomFile, int validationLevel, boolean locationTracking, TransformerContext context);
-
- /**
- * @since 4.0.0
- */
- Result extends Model> buildRawModel(
- Path pomFile, int validationLevel, boolean locationTracking, TransformerContext context);
-
- TransformerContextBuilder newTransformerContextBuilder();
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingEventCatapult.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingEventCatapult.java
index 75a8022a39..f9d68a6127 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingEventCatapult.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingEventCatapult.java
@@ -35,5 +35,10 @@ interface ModelBuildingEventCatapult {
*/
void fire(ModelBuildingListener listener, ModelBuildingEvent event);
- ModelBuildingEventCatapult BUILD_EXTENSIONS_ASSEMBLED = ModelBuildingListener::buildExtensionsAssembled;
+ ModelBuildingEventCatapult BUILD_EXTENSIONS_ASSEMBLED = new ModelBuildingEventCatapult() {
+ @Override
+ public void fire(ModelBuildingListener listener, ModelBuildingEvent event) {
+ listener.buildExtensionsAssembled(event);
+ }
+ };
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java
index 771039ae61..b4ba8d3390 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingException.java
@@ -42,7 +42,7 @@ public class ModelBuildingException extends Exception {
*
* @param model The model that could not be built, may be {@code null}.
* @param modelId The identifier of the model that could not be built, may be {@code null}.
- * @param problems The problems that cause this exception, may be {@code null}.
+ * @param problems The problems that causes this exception, may be {@code null}.
* @deprecated Use {@link #ModelBuildingException(ModelBuildingResult)} instead.
*/
@Deprecated
@@ -130,7 +130,6 @@ public class ModelBuildingException extends Exception {
return null;
}
- // Package protected for test
static String toMessage(String modelId, List problems) {
StringWriter buffer = new StringWriter(1024);
@@ -139,22 +138,19 @@ public class ModelBuildingException extends Exception {
writer.print(problems.size());
writer.print((problems.size() == 1) ? " problem was " : " problems were ");
writer.print("encountered while building the effective model");
- if (modelId != null && !modelId.isEmpty()) {
+ if (modelId != null && modelId.length() > 0) {
writer.print(" for ");
writer.print(modelId);
}
+ writer.println();
for (ModelProblem problem : problems) {
- writer.println();
- writer.print(" - [");
+ writer.print("[");
writer.print(problem.getSeverity());
writer.print("] ");
writer.print(problem.getMessage());
- String location = ModelProblemUtils.formatLocation(problem, modelId);
- if (!location.isEmpty()) {
- writer.print(" @ ");
- writer.print(location);
- }
+ writer.print(" @ ");
+ writer.println(ModelProblemUtils.formatLocation(problem, modelId));
}
return buffer.toString();
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
index ebf066d80f..d607d43391 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingRequest.java
@@ -19,7 +19,6 @@
package org.apache.maven.model.building;
import java.io.File;
-import java.nio.file.Path;
import java.util.Date;
import java.util.List;
import java.util.Properties;
@@ -55,48 +54,27 @@ public interface ModelBuildingRequest {
int VALIDATION_LEVEL_MAVEN_3_0 = 30;
/**
- * Denotes validation as performed by Maven 3.1. This validation level is meant for existing projects.
+ * Denotes validation as performed by Maven 3.1. This validation level is meant for new projects.
*/
int VALIDATION_LEVEL_MAVEN_3_1 = 31;
- /**
- * Denotes validation as performed by Maven 4.0. This validation level is meant for new projects.
- */
- int VALIDATION_LEVEL_MAVEN_4_0 = 40;
-
/**
* Denotes strict validation as recommended by the current Maven version.
*/
- int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_4_0;
+ int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_3_0;
/**
- * Gets the file model to build (with profile activation).
- * If not set, model source will be used to load file model.
+ * Gets the raw model to build. If not set, model source will be used to load raw model.
*
- * @return The file model to build or {@code null} if not set.
- * @since 4.0.0
+ * @return The raw model to build or {@code null} if not set.
*/
- Model getFileModel();
-
- /**
- * Set the file model with profile activation
- *
- * @param fileModel
- * @return This request, never {@code null}.
- * @since 4.0.0
- */
- ModelBuildingRequest setFileModel(Model fileModel);
-
- /**
- * @deprecated rawModel is never set, instead the fileModel is set
- */
- @Deprecated
Model getRawModel();
/**
- * @deprecated setting the rawModel has no effect, instead the fileModel of phase one will be set
+ * Set raw model.
+ *
+ * @param rawModel
*/
- @Deprecated
ModelBuildingRequest setRawModel(Model rawModel);
/**
@@ -108,7 +86,7 @@ public interface ModelBuildingRequest {
/**
* Sets the source of the POM to process. Eventually, either {@link #setModelSource(ModelSource)} or
- * {@link #setPomPath(Path)} must be set.
+ * {@link #setPomFile(File)} must be set.
*
* @param modelSource The source of the POM to process, may be {@code null}.
* @return This request, never {@code null}.
@@ -120,20 +98,9 @@ public interface ModelBuildingRequest {
*
* @return The POM file of the project or {@code null} if not applicable (i.e. when processing a POM from the
* repository).
- * @deprecated Use {@link #getPomPath()} instead.
*/
- @Deprecated
File getPomFile();
- /**
- * Gets the POM file of the project to build.
- *
- * @return The POM file of the project or {@code null} if not applicable (i.e. when processing a POM from the
- * repository).
- * @since 4.0.0
- */
- Path getPomPath();
-
/**
* Sets the POM file of the project to build. Note that providing the path to a POM file via this method will make
* the model builder operate in project mode. This mode is meant for effective models that are employed during the
@@ -144,25 +111,9 @@ public interface ModelBuildingRequest {
* @param pomFile The POM file of the project to build the effective model for, may be {@code null} to build the
* model of some POM from the repository.
* @return This request, never {@code null}.
- * @deprecated Use {@link #setPomPath(Path)} instead.
*/
- @Deprecated
ModelBuildingRequest setPomFile(File pomFile);
- /**
- * Sets the POM file of the project to build. Note that providing the path to a POM file via this method will make
- * the model builder operate in project mode. This mode is meant for effective models that are employed during the
- * build process of a local project. Hence the effective model will support the notion of a project directory. To
- * build the model for a POM from the repository, use {@link #setModelSource(ModelSource)} in combination with a
- * {@link FileModelSource} instead.
- *
- * @param pomPath The POM file of the project to build the effective model for, may be {@code null} to build the
- * model of some POM from the repository.
- * @return This request, never {@code null}.
- * @since 4.0.0
- */
- ModelBuildingRequest setPomPath(Path pomPath);
-
/**
* Gets the level of validation to perform on processed models.
*
@@ -382,12 +333,4 @@ public interface ModelBuildingRequest {
WorkspaceModelResolver getWorkspaceModelResolver();
ModelBuildingRequest setWorkspaceModelResolver(WorkspaceModelResolver workspaceResolver);
-
- TransformerContextBuilder getTransformerContextBuilder();
-
- ModelBuildingRequest setTransformerContextBuilder(TransformerContextBuilder contextBuilder);
-
- Path getRootDirectory();
-
- ModelBuildingRequest setRootDirectory(Path rootDirectory);
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingResult.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingResult.java
index 6f9502d04c..d3e88d5f42 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingResult.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelBuildingResult.java
@@ -33,21 +33,14 @@ public interface ModelBuildingResult {
/**
* Gets the sequence of model identifiers that denote the lineage of models from which the effective model was
- * constructed. Model identifiers should be handled as "opaque strings" and this method should be used as source
- * if navigating the linage. The first identifier from the list denotes the model on which the model builder
- * was originally invoked. The last identifier will always be the super POM.
+ * constructed. Model identifiers have the form {@code ::}. The first identifier from
+ * the list denotes the model on which the model builder was originally invoked. The last identifier will always be
+ * an empty string that by definition denotes the super POM.
*
* @return The model identifiers from the lineage of models, never {@code null}.
*/
List getModelIds();
- /**
- *
- * @return the file model
- * @since 4.0.0
- */
- Model getFileModel();
-
/**
* Gets the assembled model.
*
@@ -66,9 +59,9 @@ public interface ModelBuildingResult {
/**
* Gets the specified raw model as it was read from a model source. Apart from basic validation, a raw model has not
* undergone any updates by the model builder, e.g. reflects neither inheritance nor interpolation. The model
- * identifier should be from the collection obtained by {@link #getModelIds()}.
+ * identifier should be from the collection obtained by {@link #getModelIds()}. As a special case, an empty string
+ * can be used as the identifier for the super POM.
*
- * @see #getModelIds()
* @param modelId The identifier of the desired raw model, must not be {@code null}.
* @return The raw model or {@code null} if the specified model id does not refer to a known model.
*/
@@ -76,9 +69,9 @@ public interface ModelBuildingResult {
/**
* Gets the profiles from the specified model that were active during model building. The model identifier should be
- * from the collection obtained by {@link #getModelIds()}.
+ * from the collection obtained by {@link #getModelIds()}. As a special case, an empty string can be used as the
+ * identifier for the super POM.
*
- * @see #getModelIds()
* @param modelId The identifier of the model whose active profiles should be retrieved, must not be {@code null}.
* @return The active profiles of the model or an empty list if none or {@code null} if the specified model id does
* not refer to a known model.
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java
index 22e516a1c2..bb28e7ba3f 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCache.java
@@ -18,15 +18,11 @@
*/
package org.apache.maven.model.building;
-import java.util.function.Supplier;
-
-import org.apache.maven.building.Source;
-
/**
* Caches auxiliary data used during model building like already processed raw/effective models. The data in the cache
* is meant for exclusive consumption by the model builder and is opaque to the cache implementation. The cache key is
* formed by a combination of group id, artifact id, version and tag. The first three components generally refer to the
- * identity of a model. The tag allows for further classification of the associated data on the sole discretion of the
+ * identify of a model. The tag allows for further classification of the associated data on the sole discretion of the
* model builder.
*
* @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
@@ -34,7 +30,25 @@ import org.apache.maven.building.Source;
@Deprecated(since = "4.0.0")
public interface ModelCache {
- T computeIfAbsent(String groupId, String artifactId, String version, String tag, Supplier data);
+ /**
+ * Puts the specified data into the cache.
+ *
+ * @param groupId The group id of the cache record, must not be {@code null}.
+ * @param artifactId The artifact id of the cache record, must not be {@code null}.
+ * @param version The version of the cache record, must not be {@code null}.
+ * @param tag The tag of the cache record, must not be {@code null}.
+ * @param data The data to store in the cache, must not be {@code null}.
+ */
+ void put(String groupId, String artifactId, String version, String tag, Object data);
- T computeIfAbsent(Source path, String tag, Supplier data);
+ /**
+ * Gets the specified data from the cache.
+ *
+ * @param groupId The group id of the cache record, must not be {@code null}.
+ * @param artifactId The artifact id of the cache record, must not be {@code null}.
+ * @param version The version of the cache record, must not be {@code null}.
+ * @param tag The tag of the cache record, must not be {@code null}.
+ * @return The requested data or {@code null} if none was present in the cache.
+ */
+ Object get(String groupId, String artifactId, String version, String tag);
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCacheTag.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCacheTag.java
index 43801539d0..eeaaa66336 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCacheTag.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelCacheTag.java
@@ -18,8 +18,8 @@
*/
package org.apache.maven.model.building;
-import org.apache.maven.api.model.DependencyManagement;
-import org.apache.maven.api.model.Model;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
/**
* Describes a tag used by the model builder to access a {@link ModelCache}. This interface basically aggregates a name
@@ -46,7 +46,25 @@ interface ModelCacheTag {
Class getType();
/**
- * The tag used for the raw model without profile activation
+ * Creates a copy of the data suitable for storage in the cache. The original data to store can be mutated after the
+ * cache is populated but the state of the cache must not change so we need to make a copy.
+ *
+ * @param data The data to store in the cache, must not be {@code null}.
+ * @return The data being stored in the cache, never {@code null}.
+ */
+ T intoCache(T data);
+
+ /**
+ * Creates a copy of the data suitable for retrieval from the cache. The retrieved data can be mutated after the
+ * cache is queried but the state of the cache must not change so we need to make a copy.
+ *
+ * @param data The data to retrieve from the cache, must not be {@code null}.
+ * @return The data being retrieved from the cache, never {@code null}.
+ */
+ T fromCache(T data);
+
+ /**
+ * The tag used to denote raw model data.
*/
ModelCacheTag RAW = new ModelCacheTag() {
@@ -59,6 +77,17 @@ interface ModelCacheTag {
public Class getType() {
return ModelData.class;
}
+
+ @Override
+ public ModelData intoCache(ModelData data) {
+ Model model = (data.getModel() != null) ? data.getModel().clone() : null;
+ return new ModelData(data.getSource(), model, data.getGroupId(), data.getArtifactId(), data.getVersion());
+ }
+
+ @Override
+ public ModelData fromCache(ModelData data) {
+ return intoCache(data);
+ }
};
/**
@@ -75,21 +104,15 @@ interface ModelCacheTag {
public Class getType() {
return DependencyManagement.class;
}
- };
- /**
- * The tag used for the file model without profile activation
- * @since 4.0.0
- */
- ModelCacheTag FILE = new ModelCacheTag() {
@Override
- public String getName() {
- return "file";
+ public DependencyManagement intoCache(DependencyManagement data) {
+ return (data != null) ? data.clone() : null;
}
@Override
- public Class getType() {
- return Model.class;
+ public DependencyManagement fromCache(DependencyManagement data) {
+ return intoCache(data);
}
};
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelData.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelData.java
index 20164c10b4..3fc221bb19 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelData.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelData.java
@@ -18,10 +18,10 @@
*/
package org.apache.maven.model.building;
-import java.util.Objects;
+import java.util.List;
-import org.apache.maven.building.Source;
import org.apache.maven.model.Model;
+import org.apache.maven.model.Profile;
/**
* Holds a model along with some auxiliary information. This internal utility class assists the model builder during POM
@@ -31,9 +31,13 @@ import org.apache.maven.model.Model;
*/
@Deprecated(since = "4.0.0")
class ModelData {
- private final Source source;
+ private final ModelSource source;
- private final Model model;
+ private Model model;
+
+ private Model rawModel;
+
+ private List activeProfiles;
private String groupId;
@@ -46,7 +50,7 @@ class ModelData {
*
* @param model The model to wrap, may be {@code null}.
*/
- ModelData(Source source, Model model) {
+ ModelData(ModelSource source, Model model) {
this.source = source;
this.model = model;
}
@@ -59,15 +63,15 @@ class ModelData {
* @param artifactId The effective artifact identifier of the model, may be {@code null}.
* @param version The effective version of the model, may be {@code null}.
*/
- ModelData(Source source, Model model, String groupId, String artifactId, String version) {
+ ModelData(ModelSource source, Model model, String groupId, String artifactId, String version) {
this.source = source;
this.model = model;
- this.groupId = groupId;
- this.artifactId = artifactId;
- this.version = version;
+ setGroupId(groupId);
+ setArtifactId(artifactId);
+ setVersion(version);
}
- public Source getSource() {
+ public ModelSource getSource() {
return source;
}
@@ -80,6 +84,51 @@ class ModelData {
return model;
}
+ /**
+ * Sets the model being wrapped.
+ *
+ * @param model The model, may be {@code null}.
+ */
+ public void setModel(Model model) {
+ this.model = model;
+ }
+
+ /**
+ * Gets the raw model being wrapped.
+ *
+ * @return The raw model or {@code null} if not set.
+ */
+ public Model getRawModel() {
+ return rawModel;
+ }
+
+ /**
+ * Sets the raw model being wrapped.
+ *
+ * @param rawModel The raw model, may be {@code null}.
+ */
+ public void setRawModel(Model rawModel) {
+ this.rawModel = rawModel;
+ }
+
+ /**
+ * Gets the active profiles from the model.
+ *
+ * @return The active profiles or {@code null} if not set.
+ */
+ public List getActiveProfiles() {
+ return activeProfiles;
+ }
+
+ /**
+ * Sets the active profiles from the model.
+ *
+ * @param activeProfiles The active profiles, may be {@code null}.
+ */
+ public void setActiveProfiles(List activeProfiles) {
+ this.activeProfiles = activeProfiles;
+ }
+
/**
* Gets the effective group identifier of the model.
*
@@ -89,6 +138,15 @@ class ModelData {
return (groupId != null) ? groupId : "";
}
+ /**
+ * Sets the effective group identifier of the model.
+ *
+ * @param groupId The effective group identifier of the model, may be {@code null}.
+ */
+ public void setGroupId(String groupId) {
+ this.groupId = groupId;
+ }
+
/**
* Gets the effective artifact identifier of the model.
*
@@ -98,6 +156,15 @@ class ModelData {
return (artifactId != null) ? artifactId : "";
}
+ /**
+ * Sets the effective artifact identifier of the model.
+ *
+ * @param artifactId The effective artifact identifier of the model, may be {@code null}.
+ */
+ public void setArtifactId(String artifactId) {
+ this.artifactId = artifactId;
+ }
+
/**
* Gets the effective version of the model.
*
@@ -108,13 +175,29 @@ class ModelData {
}
/**
- * Gets unique identifier of the model
+ * Sets the effective version of the model.
+ *
+ * @param version The effective version of the model, may be {@code null}.
+ */
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ /**
+ * Gets the effective identifier of the model in the form {@code ::}.
*
* @return The effective identifier of the model, never {@code null}.
*/
public String getId() {
- // if source is null, it is the super model, which can be accessed via empty string
- return Objects.toString(source, "");
+ StringBuilder buffer = new StringBuilder(128);
+
+ buffer.append(getGroupId())
+ .append(':')
+ .append(getArtifactId())
+ .append(':')
+ .append(getVersion());
+
+ return buffer.toString();
}
@Override
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java
index 624ae09e89..4a8feb3343 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblem.java
@@ -51,9 +51,10 @@ public interface ModelProblem {
}
/**
- * Gets the identifier of the model from which the problem originated. The identifier is derived from the
- * information that is available at the point the problem occurs and as such merely serves as best effort
- * to provide information to the user to track the problem back to its origin.
+ * Gets the hint about the source of the problem. While the syntax of this hint is unspecified and depends on the
+ * creator of the problem, the general expectation is that the hint provides sufficient information to the user to
+ * track the problem back to its origin. A concrete example for such a source hint can be the file path or URL from
+ * which a POM was read.
*
* @return The hint about the source of the problem or an empty string if unknown, never {@code null}.
*/
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java
index bcbcaf575c..8a694d122c 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelProblemUtils.java
@@ -18,16 +18,15 @@
*/
package org.apache.maven.model.building;
-import java.nio.file.Path;
+import java.io.File;
import org.apache.maven.model.Model;
/**
* Assists in the handling of model problems.
*
- * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
+ * @author Benjamin Bentmann
*/
-@Deprecated(since = "4.0.0")
public class ModelProblemUtils {
/**
@@ -45,9 +44,9 @@ public class ModelProblemUtils {
buffer.append(toId(model));
- Path pomPath = model.getPomPath();
- if (pomPath != null) {
- buffer.append(" (").append(pomPath).append(')');
+ File pomFile = model.getPomFile();
+ if (pomFile != null) {
+ buffer.append(" (").append(pomFile).append(')');
}
return buffer.toString();
@@ -57,10 +56,10 @@ public class ModelProblemUtils {
String path = "";
if (model != null) {
- Path pomPath = model.getPomPath();
+ File pomFile = model.getPomFile();
- if (pomPath != null) {
- path = pomPath.toAbsolutePath().toString();
+ if (pomFile != null) {
+ path = pomFile.getAbsolutePath();
}
}
@@ -71,10 +70,7 @@ public class ModelProblemUtils {
if (model == null) {
return "";
}
- return toId(model.getDelegate());
- }
- static String toId(org.apache.maven.api.model.Model model) {
String groupId = model.getGroupId();
if (groupId == null && model.getParent() != null) {
groupId = model.getParent().getGroupId();
@@ -104,11 +100,11 @@ public class ModelProblemUtils {
static String toId(String groupId, String artifactId, String version) {
StringBuilder buffer = new StringBuilder(128);
- buffer.append((groupId != null && !groupId.isEmpty()) ? groupId : "[unknown-group-id]");
+ buffer.append((groupId != null && groupId.length() > 0) ? groupId : "[unknown-group-id]");
buffer.append(':');
- buffer.append((artifactId != null && !artifactId.isEmpty()) ? artifactId : "[unknown-artifact-id]");
+ buffer.append((artifactId != null && artifactId.length() > 0) ? artifactId : "[unknown-artifact-id]");
buffer.append(':');
- buffer.append((version != null && !version.isEmpty()) ? version : "[unknown-version]");
+ buffer.append((version != null && version.length() > 0) ? version : "[unknown-version]");
return buffer.toString();
}
@@ -129,7 +125,7 @@ public class ModelProblemUtils {
if (!problem.getModelId().equals(projectId)) {
buffer.append(problem.getModelId());
- if (!problem.getSource().isEmpty()) {
+ if (problem.getSource().length() > 0) {
if (buffer.length() > 0) {
buffer.append(", ");
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java
deleted file mode 100644
index e66814349a..0000000000
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSource3.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.model.building;
-
-import org.apache.maven.model.locator.ModelLocator;
-
-/**
- * Enhancement to the {@link ModelSource2} to support locating POM files using the {@link ModelLocator}
- * when pointing to a directory.
- *
- * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
- */
-@Deprecated(since = "4.0.0")
-public interface ModelSource3 extends ModelSource2 {
- /**
- * Returns model source identified by a path relative to this model source POM. Implementation MUST
- * accept relPath parameter values that
- *
- *
use either / or \ file path separator
- *
have .. parent directory references
- *
point either at file or directory
- *
- * If the given path points at a directory, the provided {@code ModelLocator} will be used
- * to find the POM file, else if no locator is provided, a file named 'pom.xml' needs to be
- * used by the requested model source.
- *
- * @param locator locator used to locate the pom file
- * @param relPath path of the requested model source relative to this model source POM
- * @return related model source or null if no such model source
- */
- ModelSource3 getRelatedSource(ModelLocator locator, String relPath);
-
- /**
- * When using a ModelSource3, the method with a {@code ModelLocator} argument should
- * be used instead.
- *
- * @deprecated use {@link #getRelatedSource(ModelLocator, String)} instead
- */
- @Deprecated
- default ModelSource3 getRelatedSource(String relPath) {
- return getRelatedSource(null, relPath);
- }
-}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSourceTransformer.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSourceTransformer.java
deleted file mode 100644
index ea08b588db..0000000000
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/ModelSourceTransformer.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.model.building;
-
-import java.nio.file.Path;
-
-import org.apache.maven.model.Model;
-
-/**
- * The ModelSourceTransformer is a way to transform the local pom while streaming the input.
- *
- * The {@link #transform(Path, TransformerContext, Model)} method uses a Path on purpose, to ensure the
- * local pom is the original source.
- *
- * @since 4.0.0
- * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
- */
-@Deprecated(since = "4.0.0")
-public interface ModelSourceTransformer {
- /**
- *
- * @param pomFile the pom file, cannot be null
- * @param context the context, cannot be null
- * @param model the model to transform
- * @throws TransformerException if the transformation fails
- */
- void transform(Path pomFile, TransformerContext context, Model model) throws TransformerException;
-}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/Result.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/Result.java
index c4ac3a0b53..ef68b928eb 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/Result.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/Result.java
@@ -49,7 +49,7 @@ public class Result {
* @param model
*/
public static Result success(T model) {
- return success(model, Collections.emptyList());
+ return success(model, Collections.emptyList());
}
/**
@@ -91,7 +91,7 @@ public class Result {
}
public static Result error(T model) {
- return error(model, Collections.emptyList());
+ return error(model, Collections.emptyList());
}
public static Result error(Result> result) {
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/TransformerContext.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/TransformerContext.java
deleted file mode 100644
index 3f65204827..0000000000
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/TransformerContext.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.model.building;
-
-import java.nio.file.Path;
-
-import org.apache.maven.model.Model;
-
-/**
- * Context used to transform a pom file.
- *
- * @since 4.0.0
- * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
- */
-@Deprecated(since = "4.0.0")
-public interface TransformerContext {
- /**
- * Key to get the TransformerContext from the SessionData
- */
- Object KEY = TransformerContext.class;
-
- /**
- * Get the value of the Maven user property.
- */
- String getUserProperty(String key);
-
- /**
- * Get the model based on the path when resolving the parent based on relativePath.
- *
- * @param from the requiring model
- * @param pomFile the path to the pomFile
- * @return the model, otherwise {@code null}
- */
- Model getRawModel(Path from, Path pomFile);
-
- /**
- * Get the model from the reactor based on the groupId and artifactId when resolving reactor dependencies.
- *
- * @param from the requiring model
- * @param groupId the groupId
- * @param artifactId the artifactId
- * @return the model, otherwise {@code null}
- * @throws IllegalStateException if multiple versions of the same GA are part of the reactor
- */
- Model getRawModel(Path from, String groupId, String artifactId);
-
- /**
- * Locate the POM file inside the given directory.
- */
- Path locate(Path path);
-}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/TransformerContextBuilder.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/TransformerContextBuilder.java
deleted file mode 100644
index e2b714e854..0000000000
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/building/TransformerContextBuilder.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.model.building;
-
-/**
- * The transformerContextBuilder is responsible for initializing the TransformerContext.
- * In case rawModels are missing, it could do new buildingRequests on the ModelBuilder.
- *
- * @since 4.0.0
- * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
- */
-@Deprecated(since = "4.0.0")
-public interface TransformerContextBuilder {
- /**
- * This method is used to initialize the TransformerContext
- *
- * @param request the modelBuildingRequest
- * @param problems the problemCollector
- * @return the mutable transformerContext
- */
- TransformerContext initialize(ModelBuildingRequest request, ModelProblemCollector problems);
-
- /**
- * The immutable transformerContext, can be used after the buildplan is finished.
- *
- * @return the immutable transformerContext
- */
- TransformerContext build();
-}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/composition/DefaultDependencyManagementImporter.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/composition/DefaultDependencyManagementImporter.java
index 6b542e74ac..6835c5e982 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/composition/DefaultDependencyManagementImporter.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/composition/DefaultDependencyManagementImporter.java
@@ -21,23 +21,16 @@ package org.apache.maven.model.composition;
import javax.inject.Named;
import javax.inject.Singleton;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import org.apache.maven.api.model.Dependency;
-import org.apache.maven.api.model.DependencyManagement;
-import org.apache.maven.api.model.Exclusion;
-import org.apache.maven.api.model.Model;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
import org.apache.maven.model.building.ModelBuildingRequest;
-import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProblemCollector;
-import org.apache.maven.model.building.ModelProblemCollectorRequest;
/**
* Handles the import of dependency management from other models into the target model.
@@ -50,7 +43,7 @@ import org.apache.maven.model.building.ModelProblemCollectorRequest;
public class DefaultDependencyManagementImporter implements DependencyManagementImporter {
@Override
- public Model importManagement(
+ public void importManagement(
Model target,
List extends DependencyManagement> sources,
ModelBuildingRequest request,
@@ -65,84 +58,20 @@ public class DefaultDependencyManagementImporter implements DependencyManagement
dependencies.put(dependency.getManagementKey(), dependency);
}
} else {
- depMgmt = DependencyManagement.newInstance();
+ depMgmt = new DependencyManagement();
+ target.setDependencyManagement(depMgmt);
}
- Set directDependencies = new HashSet<>(dependencies.keySet());
-
for (DependencyManagement source : sources) {
for (Dependency dependency : source.getDependencies()) {
String key = dependency.getManagementKey();
- Dependency present = dependencies.putIfAbsent(key, dependency);
- if (present != null && !equals(dependency, present) && !directDependencies.contains(key)) {
- // TODO: https://issues.apache.org/jira/browse/MNG-8004
- problems.add(new ModelProblemCollectorRequest(
- ModelProblem.Severity.WARNING, ModelProblem.Version.V40)
- .setMessage("Ignored POM import for: " + toString(dependency) + " as already imported "
- + toString(present) + ". Add the conflicting managed dependency directly "
- + "to the dependencyManagement section of the POM."));
+ if (!dependencies.containsKey(key)) {
+ dependencies.put(key, dependency);
}
}
}
- return target.withDependencyManagement(depMgmt.withDependencies(dependencies.values()));
+ depMgmt.setDependencies(new ArrayList<>(dependencies.values()));
}
- return target;
- }
-
- private String toString(Dependency dependency) {
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder
- .append(dependency.getGroupId())
- .append(":")
- .append(dependency.getArtifactId())
- .append(":")
- .append(dependency.getType());
- if (dependency.getClassifier() != null && !dependency.getClassifier().isEmpty()) {
- stringBuilder.append(":").append(dependency.getClassifier());
- }
- stringBuilder
- .append(":")
- .append(dependency.getVersion())
- .append("@")
- .append(dependency.getScope() == null ? "compile" : dependency.getScope());
- if (dependency.isOptional()) {
- stringBuilder.append("[optional]");
- }
- if (!dependency.getExclusions().isEmpty()) {
- stringBuilder.append("[").append(dependency.getExclusions().size()).append(" exclusions]");
- }
- return stringBuilder.toString();
- }
-
- private boolean equals(Dependency d1, Dependency d2) {
- return Objects.equals(d1.getGroupId(), d2.getGroupId())
- && Objects.equals(d1.getArtifactId(), d2.getArtifactId())
- && Objects.equals(d1.getVersion(), d2.getVersion())
- && Objects.equals(d1.getType(), d2.getType())
- && Objects.equals(d1.getClassifier(), d2.getClassifier())
- && Objects.equals(d1.getScope(), d2.getScope())
- && Objects.equals(d1.getSystemPath(), d2.getSystemPath())
- && Objects.equals(d1.getOptional(), d2.getOptional())
- && equals(d1.getExclusions(), d2.getExclusions());
- }
-
- private boolean equals(Collection ce1, Collection ce2) {
- if (ce1.size() == ce2.size()) {
- Iterator i1 = ce1.iterator();
- Iterator i2 = ce2.iterator();
- while (i1.hasNext() && i2.hasNext()) {
- if (!equals(i1.next(), i2.next())) {
- return false;
- }
- }
- return !i1.hasNext() && !i2.hasNext();
- }
- return false;
- }
-
- private boolean equals(Exclusion e1, Exclusion e2) {
- return Objects.equals(e1.getGroupId(), e2.getGroupId())
- && Objects.equals(e1.getArtifactId(), e2.getArtifactId());
}
}
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/composition/DependencyManagementImporter.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/composition/DependencyManagementImporter.java
index 787248e07e..2d9ae33f3d 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/composition/DependencyManagementImporter.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/composition/DependencyManagementImporter.java
@@ -20,8 +20,8 @@ package org.apache.maven.model.composition;
import java.util.List;
-import org.apache.maven.api.model.DependencyManagement;
-import org.apache.maven.api.model.Model;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Model;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblemCollector;
@@ -41,7 +41,7 @@ public interface DependencyManagementImporter {
* @param request The model building request that holds further settings, must not be {@code null}.
* @param problems The container used to collect problems that were encountered, must not be {@code null}.
*/
- Model importManagement(
+ void importManagement(
Model target,
List extends DependencyManagement> sources,
ModelBuildingRequest request,
diff --git a/compat/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java b/compat/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
index fb28922999..18070ce187 100644
--- a/compat/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
+++ b/compat/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
@@ -26,17 +26,19 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
-import org.apache.maven.api.model.InputLocation;
-import org.apache.maven.api.model.Model;
-import org.apache.maven.api.model.ModelBase;
-import org.apache.maven.api.model.Plugin;
-import org.apache.maven.api.model.PluginContainer;
-import org.apache.maven.api.model.ReportPlugin;
-import org.apache.maven.api.model.Reporting;
+import org.apache.maven.model.InputLocation;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.ModelBase;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginContainer;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.Reporting;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.merge.MavenModelMerger;
+import org.codehaus.plexus.util.StringUtils;
/**
* Handles inheritance of model values.
@@ -49,20 +51,20 @@ import org.apache.maven.model.merge.MavenModelMerger;
@Deprecated(since = "4.0.0")
public class DefaultInheritanceAssembler implements InheritanceAssembler {
+ private InheritanceModelMerger merger = new InheritanceModelMerger();
+
private static final String CHILD_DIRECTORY = "child-directory";
private static final String CHILD_DIRECTORY_PROPERTY = "project.directory";
- private final InheritanceModelMerger merger = new InheritanceModelMerger();
-
@Override
- public Model assembleModelInheritance(
+ public void assembleModelInheritance(
Model child, Model parent, ModelBuildingRequest request, ModelProblemCollector problems) {
Map