From 9bd9c3341922886e5db21f30e357d995c406c587 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 3 Dec 2026 13:59:40 +0100 Subject: [PATCH 1/2] Remove Maven 2 leftovers from maven-compat that nothing uses Deletes 15 types deprecated since Maven 3 that no code in this repository or in the apache, codehaus-plexus and mojohaus organizations references, together with the DefaultProfileManager unit test. Part of #14157. --- .../manager/WagonConfigurationException.java | 32 --- .../maven/profiles/DefaultProfileManager.java | 218 ------------------ .../profiles/ProfilesConversionUtils.java | 135 ----------- .../activation/DetectedProfileActivator.java | 34 --- .../activation/FileProfileActivator.java | 96 -------- .../activation/JdkPrefixProfileActivator.java | 84 ------- .../OperatingSystemProfileActivator.java | 135 ----------- .../profiles/activation/ProfileActivator.java | 34 --- .../SystemPropertyProfileActivator.java | 98 -------- .../org/apache/maven/project/ModelUtils.java | 60 ----- .../apache/maven/project/ProjectUtils.java | 100 -------- .../RegexBasedModelInterpolator.java | 48 ---- .../validation/DefaultModelValidator.java | 71 ------ .../project/validation/ModelValidator.java | 33 --- .../conflict/DefaultConflictResolver.java | 33 --- .../manager/DefaultProfileManagerTest.java | 202 ---------------- 16 files changed, 1413 deletions(-) delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/artifact/manager/WagonConfigurationException.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/DetectedProfileActivator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/ProjectUtils.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/validation/ModelValidator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolver.java delete mode 100644 compat/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java diff --git a/compat/maven-compat/src/main/java/org/apache/maven/artifact/manager/WagonConfigurationException.java b/compat/maven-compat/src/main/java/org/apache/maven/artifact/manager/WagonConfigurationException.java deleted file mode 100644 index 923ab3c68944..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/artifact/manager/WagonConfigurationException.java +++ /dev/null @@ -1,32 +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.artifact.manager; - -/** - */ -@Deprecated -public class WagonConfigurationException extends org.apache.maven.repository.legacy.WagonConfigurationException { - public WagonConfigurationException(String repositoryId, String message, Throwable cause) { - super(repositoryId, message, cause); - } - - public WagonConfigurationException(String repositoryId, String message) { - super(repositoryId, message); - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java b/compat/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java deleted file mode 100644 index 6960d8dded11..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/profiles/DefaultProfileManager.java +++ /dev/null @@ -1,218 +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.profiles; - -import javax.inject.Inject; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.maven.model.Activation; -import org.apache.maven.model.Profile; -import org.apache.maven.model.building.ModelProblem; -import org.apache.maven.model.profile.DefaultProfileActivationContext; -import org.apache.maven.model.profile.ProfileSelector; -import org.apache.maven.profiles.activation.ProfileActivationException; -import org.codehaus.plexus.MutablePlexusContainer; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.logging.Logger; - -/** - * DefaultProfileManager - */ -@Deprecated -public class DefaultProfileManager implements ProfileManager { - - @Inject - private Logger logger; - - @Inject - private ProfileSelector profileSelector; - - private List activatedIds = new ArrayList<>(); - - private List deactivatedIds = new ArrayList<>(); - - private List defaultIds = new ArrayList<>(); - - private Map profilesById = new LinkedHashMap<>(); - - private Properties requestProperties; - - /** - * @deprecated without passing in the system properties, the SystemPropertiesProfileActivator will not work - * correctly in embedded environments. - */ - @Deprecated - public DefaultProfileManager(PlexusContainer container) { - this(container, null); - } - - /** - * the properties passed to the profile manager are the props that - * are passed to maven, possibly containing profile activator properties - * - */ - public DefaultProfileManager(PlexusContainer container, Properties props) { - try { - this.profileSelector = container.lookup(ProfileSelector.class); - this.logger = ((MutablePlexusContainer) container).getLogger(); - } catch (ComponentLookupException e) { - throw new IllegalStateException(e); - } - this.requestProperties = props; - } - - @Override - public Properties getRequestProperties() { - return requestProperties; - } - - @Override - public Map getProfilesById() { - return profilesById; - } - - /* (non-Javadoc) - * @see org.apache.maven.profiles.ProfileManager#addProfile(org.apache.maven.model.Profile) - */ - @Override - public void addProfile(Profile profile) { - String profileId = profile.getId(); - - Profile existing = profilesById.get(profileId); - if (existing != null) { - logger.warn("Overriding profile: '" + profileId + "' (source: " + existing.getSource() - + ") with new instance from source: " + profile.getSource()); - } - - profilesById.put(profile.getId(), profile); - - Activation activation = profile.getActivation(); - - if (activation != null && activation.isActiveByDefault()) { - activateAsDefault(profileId); - } - } - - /* (non-Javadoc) - * @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.lang.String) - */ - @Override - public void explicitlyActivate(String profileId) { - if (!activatedIds.contains(profileId)) { - logger.debug("Profile with id: '" + profileId + "' has been explicitly activated."); - - activatedIds.add(profileId); - } - } - - /* (non-Javadoc) - * @see org.apache.maven.profiles.ProfileManager#explicitlyActivate(java.util.List) - */ - @Override - public void explicitlyActivate(List profileIds) { - for (String profileId1 : profileIds) { - explicitlyActivate(profileId1); - } - } - - /* (non-Javadoc) - * @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.lang.String) - */ - @Override - public void explicitlyDeactivate(String profileId) { - if (!deactivatedIds.contains(profileId)) { - logger.debug("Profile with id: '" + profileId + "' has been explicitly deactivated."); - - deactivatedIds.add(profileId); - } - } - - /* (non-Javadoc) - * @see org.apache.maven.profiles.ProfileManager#explicitlyDeactivate(java.util.List) - */ - @Override - public void explicitlyDeactivate(List profileIds) { - for (String profileId1 : profileIds) { - explicitlyDeactivate(profileId1); - } - } - - /* (non-Javadoc) - * @see org.apache.maven.profiles.ProfileManager#getActiveProfiles() - */ - @Override - public List getActiveProfiles() throws ProfileActivationException { - DefaultProfileActivationContext context = new DefaultProfileActivationContext(); - context.setActiveProfileIds(activatedIds); - context.setInactiveProfileIds(deactivatedIds); - context.setSystemProperties(System.getProperties()); - context.setUserProperties(requestProperties); - - final List errors = new ArrayList<>(); - - List profiles = profileSelector.getActiveProfiles(profilesById.values(), context, req -> { - if (!ModelProblem.Severity.WARNING.equals(req.getSeverity())) { - errors.add(new ProfileActivationException(req.getMessage(), req.getException())); - } - }); - - if (!errors.isEmpty()) { - throw errors.get(0); - } - - return profiles; - } - - /* (non-Javadoc) - * @see org.apache.maven.profiles.ProfileManager#addProfiles(java.util.List) - */ - @Override - public void addProfiles(List profiles) { - for (Profile profile1 : profiles) { - addProfile(profile1); - } - } - - public void activateAsDefault(String profileId) { - if (!defaultIds.contains(profileId)) { - defaultIds.add(profileId); - } - } - - @Override - public List getExplicitlyActivatedIds() { - return activatedIds; - } - - @Override - public List getExplicitlyDeactivatedIds() { - return deactivatedIds; - } - - @Override - public List getIdsActivatedByDefault() { - return defaultIds; - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java b/compat/maven-compat/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java deleted file mode 100644 index e0e77d2800cc..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java +++ /dev/null @@ -1,135 +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.profiles; - -import java.util.List; - -import org.apache.maven.model.Activation; -import org.apache.maven.model.ActivationFile; -import org.apache.maven.model.ActivationProperty; -import org.apache.maven.model.Profile; -import org.apache.maven.model.Repository; - -/** - * ProfilesConversionUtils - */ -@Deprecated -public class ProfilesConversionUtils { - private ProfilesConversionUtils() {} - - public static Profile convertFromProfileXmlProfile(org.apache.maven.profiles.Profile profileXmlProfile) { - Profile profile = new Profile(); - - profile.setId(profileXmlProfile.getId()); - - profile.setSource("profiles.xml"); - - org.apache.maven.profiles.Activation profileActivation = profileXmlProfile.getActivation(); - - if (profileActivation != null) { - Activation activation = new Activation(); - - activation.setActiveByDefault(profileActivation.isActiveByDefault()); - - activation.setJdk(profileActivation.getJdk()); - - org.apache.maven.profiles.ActivationProperty profileProp = profileActivation.getProperty(); - - if (profileProp != null) { - ActivationProperty prop = new ActivationProperty(); - - prop.setName(profileProp.getName()); - prop.setValue(profileProp.getValue()); - - activation.setProperty(prop); - } - - ActivationOS profileOs = profileActivation.getOs(); - - if (profileOs != null) { - org.apache.maven.model.ActivationOS os = new org.apache.maven.model.ActivationOS(); - - os.setArch(profileOs.getArch()); - os.setFamily(profileOs.getFamily()); - os.setName(profileOs.getName()); - os.setVersion(profileOs.getVersion()); - - activation.setOs(os); - } - - org.apache.maven.profiles.ActivationFile profileFile = profileActivation.getFile(); - - if (profileFile != null) { - ActivationFile file = new ActivationFile(); - - file.setExists(profileFile.getExists()); - file.setMissing(profileFile.getMissing()); - - activation.setFile(file); - } - - profile.setActivation(activation); - } - - profile.setProperties(profileXmlProfile.getProperties()); - - List repos = profileXmlProfile.getRepositories(); - if (repos != null) { - for (Object repo : repos) { - profile.addRepository(convertFromProfileXmlRepository((org.apache.maven.profiles.Repository) repo)); - } - } - - List pluginRepos = profileXmlProfile.getPluginRepositories(); - if (pluginRepos != null) { - for (Object pluginRepo : pluginRepos) { - profile.addPluginRepository( - convertFromProfileXmlRepository((org.apache.maven.profiles.Repository) pluginRepo)); - } - } - - return profile; - } - - private static Repository convertFromProfileXmlRepository(org.apache.maven.profiles.Repository profileXmlRepo) { - Repository repo = new Repository(); - - repo.setId(profileXmlRepo.getId()); - repo.setLayout(profileXmlRepo.getLayout()); - repo.setName(profileXmlRepo.getName()); - repo.setUrl(profileXmlRepo.getUrl()); - - if (profileXmlRepo.getSnapshots() != null) { - repo.setSnapshots(convertRepositoryPolicy(profileXmlRepo.getSnapshots())); - } - if (profileXmlRepo.getReleases() != null) { - repo.setReleases(convertRepositoryPolicy(profileXmlRepo.getReleases())); - } - - return repo; - } - - private static org.apache.maven.model.RepositoryPolicy convertRepositoryPolicy(RepositoryPolicy profileXmlRepo) { - org.apache.maven.model.RepositoryPolicy policy = new org.apache.maven.model.RepositoryPolicy(); - policy.setEnabled(profileXmlRepo.isEnabled()); - policy.setUpdatePolicy(profileXmlRepo.getUpdatePolicy()); - policy.setChecksumPolicy(profileXmlRepo.getChecksumPolicy()); - return policy; - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/DetectedProfileActivator.java b/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/DetectedProfileActivator.java deleted file mode 100644 index 5afd5788c606..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/DetectedProfileActivator.java +++ /dev/null @@ -1,34 +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.profiles.activation; - -import org.apache.maven.model.Profile; - -/** - * DetectedProfileActivator - */ -@Deprecated -public abstract class DetectedProfileActivator implements ProfileActivator { - @Override - public boolean canDetermineActivation(Profile profile) { - return canDetectActivation(profile); - } - - protected abstract boolean canDetectActivation(Profile profile); -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java b/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java deleted file mode 100644 index 8a1b82a8e99c..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/FileProfileActivator.java +++ /dev/null @@ -1,96 +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.profiles.activation; - -import java.io.File; -import java.io.IOException; - -import org.apache.maven.model.Activation; -import org.apache.maven.model.ActivationFile; -import org.apache.maven.model.Profile; -import org.codehaus.plexus.interpolation.EnvarBasedValueSource; -import org.codehaus.plexus.interpolation.InterpolationException; -import org.codehaus.plexus.interpolation.MapBasedValueSource; -import org.codehaus.plexus.interpolation.RegexBasedInterpolator; -import org.codehaus.plexus.logging.LogEnabled; -import org.codehaus.plexus.logging.Logger; - -/** - * FileProfileActivator - */ -@Deprecated -public class FileProfileActivator extends DetectedProfileActivator implements LogEnabled { - private Logger logger; - - @Override - protected boolean canDetectActivation(Profile profile) { - return profile.getActivation() != null && profile.getActivation().getFile() != null; - } - - @Override - public boolean isActive(Profile profile) { - Activation activation = profile.getActivation(); - - ActivationFile actFile = activation.getFile(); - - if (actFile != null) { - // check if the file exists, if it does then the profile will be active - String fileString = actFile.getExists(); - - RegexBasedInterpolator interpolator = new RegexBasedInterpolator(); - try { - interpolator.addValueSource(new EnvarBasedValueSource()); - } catch (IOException e) { - // ignored - } - interpolator.addValueSource(new MapBasedValueSource(System.getProperties())); - - try { - if (fileString != null && !fileString.isEmpty()) { - fileString = interpolator.interpolate(fileString, "").replace("\\", "/"); - File file = new File(fileString); - return file.exists(); - } - - // check if the file is missing, if it is then the profile will be active - fileString = actFile.getMissing(); - - if (fileString != null && !fileString.isEmpty()) { - fileString = interpolator.interpolate(fileString, "").replace("\\", "/"); - File file = new File(fileString); - return !file.exists(); - } - } catch (InterpolationException e) { - if (logger.isDebugEnabled()) { - logger.debug("Failed to interpolate missing file location for profile activator: " + fileString, e); - } else { - logger.warn("Failed to interpolate missing file location for profile activator: " + fileString - + ", enable verbose output (-X) for more details"); - } - } - } - - return false; - } - - @Override - public void enableLogging(Logger logger) { - this.logger = logger; - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java b/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java deleted file mode 100644 index 223a33c00d8c..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/JdkPrefixProfileActivator.java +++ /dev/null @@ -1,84 +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.profiles.activation; - -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.Profile; - -/** - * JdkPrefixProfileActivator - */ -@Deprecated -public class JdkPrefixProfileActivator extends DetectedProfileActivator { - private static final String JDK_VERSION = System.getProperty("java.version"); - - @Override - public boolean isActive(Profile profile) throws ProfileActivationException { - Activation activation = profile.getActivation(); - - String jdk = activation.getJdk(); - - // null case is covered by canDetermineActivation(), so we can do a straight startsWith() here. - if (jdk.startsWith("[") || jdk.startsWith("(")) { - try { - return matchJdkVersionRange(jdk); - } catch (InvalidVersionSpecificationException e) { - throw new ProfileActivationException( - "Invalid JDK version in profile '" + profile.getId() + "': " + e.getMessage()); - } - } - - boolean reverse = false; - - if (jdk.startsWith("!")) { - reverse = true; - jdk = jdk.substring(1); - } - - if (getJdkVersion().startsWith(jdk)) { - return !reverse; - } else { - return reverse; - } - } - - private boolean matchJdkVersionRange(String jdk) throws InvalidVersionSpecificationException { - VersionRange jdkVersionRange = VersionRange.createFromVersionSpec(convertJdkToMavenVersion(jdk)); - DefaultArtifactVersion jdkVersion = new DefaultArtifactVersion(convertJdkToMavenVersion(getJdkVersion())); - return jdkVersionRange.containsVersion(jdkVersion); - } - - private String convertJdkToMavenVersion(String jdk) { - return jdk.replace("_", "-"); - } - - protected String getJdkVersion() { - return JDK_VERSION; - } - - @Override - protected boolean canDetectActivation(Profile profile) { - return profile.getActivation() != null - && profile.getActivation().getJdk() != null - && !profile.getActivation().getJdk().isEmpty(); - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java b/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java deleted file mode 100644 index 0c7944b53992..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/OperatingSystemProfileActivator.java +++ /dev/null @@ -1,135 +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.profiles.activation; - -import org.apache.maven.model.Activation; -import org.apache.maven.model.ActivationOS; -import org.apache.maven.model.Profile; -import org.apache.maven.utils.Os; - -/** - * OperatingSystemProfileActivator - */ -@Deprecated -public class OperatingSystemProfileActivator implements ProfileActivator { - - @Override - public boolean canDetermineActivation(Profile profile) { - Activation activation = profile.getActivation(); - return activation != null && activation.getOs() != null; - } - - @Override - public boolean isActive(Profile profile) { - Activation activation = profile.getActivation(); - ActivationOS os = activation.getOs(); - - boolean result = ensureAtLeastOneNonNull(os); - - if (result && os.getFamily() != null) { - result = determineFamilyMatch(os.getFamily()); - } - if (result && os.getName() != null) { - result = determineNameMatch(os.getName()); - } - if (result && os.getArch() != null) { - result = determineArchMatch(os.getArch()); - } - if (result && os.getVersion() != null) { - result = determineVersionMatch(os.getVersion()); - } - return result; - } - - private boolean ensureAtLeastOneNonNull(ActivationOS os) { - return os.getArch() != null || os.getFamily() != null || os.getName() != null || os.getVersion() != null; - } - - private boolean determineVersionMatch(String version) { - String test = version; - boolean reverse = false; - - if (test.startsWith("!")) { - reverse = true; - test = test.substring(1); - } - - boolean result = Os.OS_VERSION.equals(test); - - if (reverse) { - return !result; - } else { - return result; - } - } - - private boolean determineArchMatch(String arch) { - String test = arch; - boolean reverse = false; - - if (test.startsWith("!")) { - reverse = true; - test = test.substring(1); - } - - boolean result = Os.OS_ARCH.equals(test); - - if (reverse) { - return !result; - } else { - return result; - } - } - - private boolean determineNameMatch(String name) { - String test = name; - boolean reverse = false; - - if (test.startsWith("!")) { - reverse = true; - test = test.substring(1); - } - - boolean result = Os.OS_NAME.equals(test); - - if (reverse) { - return !result; - } else { - return result; - } - } - - private boolean determineFamilyMatch(String family) { - String test = family; - boolean reverse = false; - - if (test.startsWith("!")) { - reverse = true; - test = test.substring(1); - } - - boolean result = Os.isFamily(test); - - if (reverse) { - return !result; - } else { - return result; - } - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java b/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java deleted file mode 100644 index fc8a6e7f00f5..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/ProfileActivator.java +++ /dev/null @@ -1,34 +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.profiles.activation; - -import org.apache.maven.model.Profile; - -/** - * ProfileActivator - */ -@Deprecated -public interface ProfileActivator { - - String ROLE = ProfileActivator.class.getName(); - - boolean canDetermineActivation(Profile profile); - - boolean isActive(Profile profile) throws ProfileActivationException; -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java b/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java deleted file mode 100644 index 32a29f8aedd9..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/profiles/activation/SystemPropertyProfileActivator.java +++ /dev/null @@ -1,98 +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.profiles.activation; - -import java.util.Properties; - -import org.apache.maven.model.Activation; -import org.apache.maven.model.ActivationProperty; -import org.apache.maven.model.Profile; -import org.codehaus.plexus.context.Context; -import org.codehaus.plexus.context.ContextException; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; - -/** - * SystemPropertyProfileActivator - */ -@Deprecated -public class SystemPropertyProfileActivator extends DetectedProfileActivator implements Contextualizable { - private Properties properties; - - @Override - public void contextualize(Context context) throws ContextException { - properties = (Properties) context.get("SystemProperties"); - } - - @Override - protected boolean canDetectActivation(Profile profile) { - return profile.getActivation() != null && profile.getActivation().getProperty() != null; - } - - @Override - public boolean isActive(Profile profile) throws ProfileActivationException { - Activation activation = profile.getActivation(); - - ActivationProperty property = activation.getProperty(); - - if (property != null) { - String name = property.getName(); - boolean reverseName = false; - - if (name == null) { - throw new ProfileActivationException( - "The property name is required to activate the profile '" + profile.getId() + "'"); - } - - if (name.startsWith("!")) { - reverseName = true; - name = name.substring(1); - } - - String sysValue = properties.getProperty(name); - - String propValue = property.getValue(); - if (propValue != null && !propValue.isEmpty()) { - boolean reverseValue = false; - if (propValue.startsWith("!")) { - reverseValue = true; - propValue = propValue.substring(1); - } - - // we have a value, so it has to match the system value... - boolean result = propValue.equals(sysValue); - - if (reverseValue) { - return !result; - } else { - return result; - } - } else { - boolean result = sysValue != null && !sysValue.isEmpty(); - - if (reverseName) { - return !result; - } else { - return result; - } - } - } - - return false; - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java b/compat/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java deleted file mode 100644 index baf054a48a2a..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java +++ /dev/null @@ -1,60 +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.project; - -import java.util.List; - -import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginContainer; - -/** @deprecated */ -@Deprecated -public final class ModelUtils { - - /** - * This should be the resulting ordering of plugins after merging: - *

- * Given: - *

-     * parent: X -> A -> B -> D -> E
-     * child: Y -> A -> C -> D -> F
-     * 
- * Result: - *
-     * X -> Y -> A -> B -> C -> D -> E -> F
-     * 
- */ - public static void mergePluginLists( - PluginContainer childContainer, PluginContainer parentContainer, boolean handleAsInheritance) { - throw new UnsupportedOperationException(); - } - - public static List orderAfterMerge( - List merged, List highPrioritySource, List lowPrioritySource) { - throw new UnsupportedOperationException(); - } - - public static void mergePluginDefinitions(Plugin child, Plugin parent, boolean handleAsInheritance) { - throw new UnsupportedOperationException(); - } - - public static void mergeFilterLists(List childFilters, List parentFilters) { - throw new UnsupportedOperationException(); - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/ProjectUtils.java b/compat/maven-compat/src/main/java/org/apache/maven/project/ProjectUtils.java deleted file mode 100644 index 15c2158856d2..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/ProjectUtils.java +++ /dev/null @@ -1,100 +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.project; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.maven.artifact.InvalidRepositoryException; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.model.DeploymentRepository; -import org.apache.maven.model.Repository; -import org.apache.maven.plugin.LegacySupport; -import org.apache.maven.repository.RepositorySystem; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.eclipse.aether.RepositorySystemSession; - -// This class needs to stick around because it was exposed the remote resources plugin started using it instead of -// getting the repositories from the project. - -/** - * ProjectUtils - */ -@Deprecated -public final class ProjectUtils { - - private ProjectUtils() {} - - public static List buildArtifactRepositories( - List repositories, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c) - throws InvalidRepositoryException { - - List remoteRepositories = new ArrayList<>(); - - for (Repository r : repositories) { - remoteRepositories.add(buildArtifactRepository(r, artifactRepositoryFactory, c)); - } - - return remoteRepositories; - } - - public static ArtifactRepository buildDeploymentArtifactRepository( - DeploymentRepository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c) - throws InvalidRepositoryException { - return buildArtifactRepository(repo, artifactRepositoryFactory, c); - } - - public static ArtifactRepository buildArtifactRepository( - Repository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer c) - throws InvalidRepositoryException { - RepositorySystem repositorySystem = rs(c); - RepositorySystemSession session = rss(c); - - ArtifactRepository repository = repositorySystem.buildArtifactRepository(repo); - - if (session != null) { - repositorySystem.injectMirror(session, Arrays.asList(repository)); - repositorySystem.injectProxy(session, Arrays.asList(repository)); - repositorySystem.injectAuthentication(session, Arrays.asList(repository)); - } - - return repository; - } - - private static RepositorySystem rs(PlexusContainer c) { - try { - return c.lookup(RepositorySystem.class); - } catch (ComponentLookupException e) { - throw new IllegalStateException(e); - } - } - - private static RepositorySystemSession rss(PlexusContainer c) { - try { - LegacySupport legacySupport = c.lookup(LegacySupport.class); - - return legacySupport.getRepositorySession(); - } catch (ComponentLookupException e) { - throw new IllegalStateException(e); - } - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java b/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java deleted file mode 100644 index 6449da7416ce..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java +++ /dev/null @@ -1,48 +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.project.interpolation; - -import java.io.IOException; -import java.util.Properties; - -import org.apache.maven.project.path.PathTranslator; -import org.codehaus.plexus.interpolation.Interpolator; -import org.codehaus.plexus.interpolation.RegexBasedInterpolator; - -/** - * Use a regular expression search to find and resolve expressions within the POM. - * - * TODO Consolidate this logic with the PluginParameterExpressionEvaluator, minus deprecations/bans. - */ -@Deprecated -public class RegexBasedModelInterpolator extends AbstractStringBasedModelInterpolator { - - public RegexBasedModelInterpolator() throws IOException {} - - public RegexBasedModelInterpolator(PathTranslator pathTranslator) { - super(pathTranslator); - } - - public RegexBasedModelInterpolator(Properties envars) {} - - @Override - protected Interpolator createInterpolator() { - return new RegexBasedInterpolator(true); - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/compat/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java deleted file mode 100644 index 59f623e5e28c..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java +++ /dev/null @@ -1,71 +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.project.validation; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.model.Model; -import org.apache.maven.model.building.DefaultModelBuildingRequest; -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; - -/** - */ -@Deprecated -@Named -@Singleton -public class DefaultModelValidator implements ModelValidator { - - @Inject - private org.apache.maven.model.validation.ModelValidator modelValidator; - - @Override - public ModelValidationResult validate(Model model) { - ModelValidationResult result = new ModelValidationResult(); - - ModelBuildingRequest request = - new DefaultModelBuildingRequest().setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0); - - SimpleModelProblemCollector problems = new SimpleModelProblemCollector(result); - - modelValidator.validateEffectiveModel(model, request, problems); - - return result; - } - - private static class SimpleModelProblemCollector implements ModelProblemCollector { - - ModelValidationResult result; - - SimpleModelProblemCollector(ModelValidationResult result) { - this.result = result; - } - - @Override - public void add(ModelProblemCollectorRequest req) { - if (!ModelProblem.Severity.WARNING.equals(req.getSeverity())) { - result.addMessage(req.getMessage()); - } - } - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/validation/ModelValidator.java b/compat/maven-compat/src/main/java/org/apache/maven/project/validation/ModelValidator.java deleted file mode 100644 index a9bd44bf7946..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/validation/ModelValidator.java +++ /dev/null @@ -1,33 +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.project.validation; - -import org.apache.maven.model.Model; - -/** - * Checks the model for missing or invalid values. - * - */ -@Deprecated -public interface ModelValidator { - - String ROLE = ModelValidator.class.getName(); - - ModelValidationResult validate(Model model); -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolver.java b/compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolver.java deleted file mode 100644 index a3a06800f3ec..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/conflict/DefaultConflictResolver.java +++ /dev/null @@ -1,33 +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.repository.legacy.resolver.conflict; - -import javax.inject.Named; -import javax.inject.Singleton; - -/** - * The default conflict resolver that delegates to the nearest strategy. - * - * @see NearestConflictResolver - * @deprecated As of 3.0, use a specific implementation instead, e.g. {@link NearestConflictResolver} - */ -@Deprecated -@Named -@Singleton -public class DefaultConflictResolver extends NearestConflictResolver {} diff --git a/compat/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java b/compat/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java deleted file mode 100644 index d0d798b7e007..000000000000 --- a/compat/maven-compat/src/test/java/org/apache/maven/profiles/manager/DefaultProfileManagerTest.java +++ /dev/null @@ -1,202 +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.profiles.manager; - -import javax.inject.Inject; - -import java.util.List; -import java.util.Properties; - -import org.apache.maven.model.Activation; -import org.apache.maven.model.ActivationProperty; -import org.apache.maven.model.Profile; -import org.apache.maven.profiles.DefaultProfileManager; -import org.apache.maven.profiles.ProfileManager; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.testing.PlexusTest; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@PlexusTest -@Deprecated -class DefaultProfileManagerTest { - - @Inject - PlexusContainer container; - - protected PlexusContainer getContainer() { - return container; - } - - @Test - void testShouldActivateDefaultProfile() throws Exception { - Profile notActivated = new Profile(); - notActivated.setId("notActivated"); - - Activation nonActivation = new Activation(); - - nonActivation.setJdk("19.2"); - - notActivated.setActivation(nonActivation); - - Profile defaultActivated = new Profile(); - defaultActivated.setId("defaultActivated"); - - Activation defaultActivation = new Activation(); - - defaultActivation.setActiveByDefault(true); - - defaultActivated.setActivation(defaultActivation); - - Properties props = System.getProperties(); - - ProfileManager profileManager = new DefaultProfileManager(getContainer(), props); - - profileManager.addProfile(notActivated); - profileManager.addProfile(defaultActivated); - - List active = profileManager.getActiveProfiles(); - - assertNotNull(active); - assertEquals(1, active.size()); - assertEquals("defaultActivated", ((Profile) active.get(0)).getId()); - } - - @Test - void testShouldNotActivateDefaultProfile() throws Exception { - Profile syspropActivated = new Profile(); - syspropActivated.setId("syspropActivated"); - - Activation syspropActivation = new Activation(); - - ActivationProperty syspropProperty = new ActivationProperty(); - syspropProperty.setName("java.version"); - - syspropActivation.setProperty(syspropProperty); - - syspropActivated.setActivation(syspropActivation); - - Profile defaultActivated = new Profile(); - defaultActivated.setId("defaultActivated"); - - Activation defaultActivation = new Activation(); - - defaultActivation.setActiveByDefault(true); - - defaultActivated.setActivation(defaultActivation); - - Properties props = System.getProperties(); - - ProfileManager profileManager = new DefaultProfileManager(getContainer(), props); - - profileManager.addProfile(syspropActivated); - profileManager.addProfile(defaultActivated); - - List active = profileManager.getActiveProfiles(); - - assertNotNull(active); - assertEquals(1, active.size()); - assertEquals("syspropActivated", ((Profile) active.get(0)).getId()); - } - - @Test - void testShouldNotActivateReversalOfPresentSystemProperty() throws Exception { - Profile syspropActivated = new Profile(); - syspropActivated.setId("syspropActivated"); - - Activation syspropActivation = new Activation(); - - ActivationProperty syspropProperty = new ActivationProperty(); - syspropProperty.setName("!java.version"); - - syspropActivation.setProperty(syspropProperty); - - syspropActivated.setActivation(syspropActivation); - - Properties props = System.getProperties(); - - ProfileManager profileManager = new DefaultProfileManager(getContainer(), props); - - profileManager.addProfile(syspropActivated); - - List active = profileManager.getActiveProfiles(); - - assertNotNull(active); - assertEquals(0, active.size()); - } - - @Test - void testShouldOverrideAndActivateInactiveProfile() throws Exception { - Profile syspropActivated = new Profile(); - syspropActivated.setId("syspropActivated"); - - Activation syspropActivation = new Activation(); - - ActivationProperty syspropProperty = new ActivationProperty(); - syspropProperty.setName("!java.version"); - - syspropActivation.setProperty(syspropProperty); - - syspropActivated.setActivation(syspropActivation); - - Properties props = System.getProperties(); - - ProfileManager profileManager = new DefaultProfileManager(getContainer(), props); - - profileManager.addProfile(syspropActivated); - - profileManager.explicitlyActivate("syspropActivated"); - - List active = profileManager.getActiveProfiles(); - - assertNotNull(active); - assertEquals(1, active.size()); - assertEquals("syspropActivated", ((Profile) active.get(0)).getId()); - } - - @Test - void testShouldOverrideAndDeactivateActiveProfile() throws Exception { - Profile syspropActivated = new Profile(); - syspropActivated.setId("syspropActivated"); - - Activation syspropActivation = new Activation(); - - ActivationProperty syspropProperty = new ActivationProperty(); - syspropProperty.setName("java.version"); - - syspropActivation.setProperty(syspropProperty); - - syspropActivated.setActivation(syspropActivation); - - Properties props = System.getProperties(); - - ProfileManager profileManager = new DefaultProfileManager(getContainer(), props); - - profileManager.addProfile(syspropActivated); - - profileManager.explicitlyDeactivate("syspropActivated"); - - List active = profileManager.getActiveProfiles(); - - assertNotNull(active); - assertEquals(0, active.size()); - } -} From db21d59321c508eaacc3731c24aabea1e8c1f3f6 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 3 Dec 2026 15:13:24 +0100 Subject: [PATCH 2/2] Remove the legacy project interpolation and RuntimeInformation from maven-compat Deletes the org.apache.maven.project.interpolation package and execution.RuntimeInformation, both deprecated since Maven 3, with the MNG-5445 IT that tested the legacy interpolator. MNG-3652 now reads the Maven version through org.apache.maven.rtinfo.RuntimeInformation. Part of #14157. --- .../execution/DefaultRuntimeInformation.java | 59 --- .../maven/execution/RuntimeInformation.java | 31 -- .../AbstractStringBasedModelInterpolator.java | 340 ------------------ .../BuildTimestampValueSource.java | 56 --- .../ModelInterpolationException.java | 59 --- .../interpolation/ModelInterpolator.java | 55 --- .../PathTranslatingPostProcessor.java | 60 ---- .../StringSearchModelInterpolator.java | 303 ---------------- .../StringSearchModelInterpolatorTest.java | 41 --- ...gacyStringSearchModelInterpolatorTest.java | 55 --- .../org/apache/maven/its/mng3652/MyMojo.java | 4 +- .../pom.xml | 95 ----- .../plugin/coreit/PathInterpolationMojo.java | 63 ---- .../src/site/site.xml | 33 -- .../src/test/resources/mng-5445/pom.xml | 35 -- 15 files changed, 2 insertions(+), 1287 deletions(-) delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/BuildTimestampValueSource.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/ModelInterpolationException.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java delete mode 100644 compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java delete mode 100644 compat/maven-compat/src/test/java/org/apache/maven/project/interpolation/StringSearchModelInterpolatorTest.java delete mode 100644 its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5445LegacyStringSearchModelInterpolatorTest.java delete mode 100644 its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/pom.xml delete mode 100644 its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/src/main/java/org/apache/maven/plugin/coreit/PathInterpolationMojo.java delete mode 100644 its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/src/site/site.xml delete mode 100644 its/core-it-suite/src/test/resources/mng-5445/pom.xml diff --git a/compat/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java b/compat/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java deleted file mode 100644 index 3a1263f541dd..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.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.execution; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; - -/** - * Describes runtime information about the application. - * - */ -@Deprecated -@Named -@Singleton -public class DefaultRuntimeInformation implements RuntimeInformation, Initializable { - - @Inject - private org.apache.maven.rtinfo.RuntimeInformation rtInfo; - - private ArtifactVersion applicationVersion; - - @Override - public ArtifactVersion getApplicationVersion() { - return applicationVersion; - } - - @Override - public void initialize() throws InitializationException { - String mavenVersion = rtInfo.getMavenVersion(); - - if (mavenVersion == null || mavenVersion.isEmpty()) { - throw new InitializationException("Unable to read Maven version from maven-core"); - } - - applicationVersion = new DefaultArtifactVersion(mavenVersion); - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java b/compat/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java deleted file mode 100644 index e16946516128..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java +++ /dev/null @@ -1,31 +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.execution; - -import org.apache.maven.artifact.versioning.ArtifactVersion; - -/** - * Describes runtime information about the application. - * - * @deprecated Use {@link org.apache.maven.rtinfo.RuntimeInformation} instead. - */ -@Deprecated -public interface RuntimeInformation { - ArtifactVersion getApplicationVersion(); -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java b/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java deleted file mode 100644 index 5fa63fc61099..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java +++ /dev/null @@ -1,340 +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.project.interpolation; - -import javax.inject.Inject; -import javax.xml.stream.XMLStreamException; - -import java.io.File; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.maven.model.Model; -import org.apache.maven.model.v4.MavenStaxReader; -import org.apache.maven.model.v4.MavenStaxWriter; -import org.apache.maven.project.DefaultProjectBuilderConfiguration; -import org.apache.maven.project.ProjectBuilderConfiguration; -import org.apache.maven.project.path.PathTranslator; -import org.codehaus.plexus.interpolation.AbstractValueSource; -import org.codehaus.plexus.interpolation.InterpolationException; -import org.codehaus.plexus.interpolation.InterpolationPostProcessor; -import org.codehaus.plexus.interpolation.Interpolator; -import org.codehaus.plexus.interpolation.MapBasedValueSource; -import org.codehaus.plexus.interpolation.ObjectBasedValueSource; -import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor; -import org.codehaus.plexus.interpolation.PrefixedObjectValueSource; -import org.codehaus.plexus.interpolation.PrefixedValueSourceWrapper; -import org.codehaus.plexus.interpolation.RecursionInterceptor; -import org.codehaus.plexus.interpolation.ValueSource; -import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; - -/** - * Use a regular expression search to find and resolve expressions within the POM. - * - * TODO Consolidate this logic with the PluginParameterExpressionEvaluator, minus deprecations/bans. - */ -@Deprecated -public abstract class AbstractStringBasedModelInterpolator extends AbstractLogEnabled - implements ModelInterpolator, Initializable { - - private static final List PROJECT_PREFIXES = Arrays.asList("pom.", "project."); - - private static final List TRANSLATED_PATH_EXPRESSIONS; - - static { - List translatedPrefixes = new ArrayList<>(); - - // MNG-1927, MNG-2124, MNG-3355: - // If the build section is present and the project directory is non-null, we should make - // sure interpolation of the directories below uses translated paths. - // Afterward, we'll double back and translate any paths that weren't covered during interpolation via the - // code below... - translatedPrefixes.add("build.directory"); - translatedPrefixes.add("build.outputDirectory"); - translatedPrefixes.add("build.testOutputDirectory"); - translatedPrefixes.add("build.sourceDirectory"); - translatedPrefixes.add("build.testSourceDirectory"); - translatedPrefixes.add("build.scriptSourceDirectory"); - translatedPrefixes.add("reporting.outputDirectory"); - - TRANSLATED_PATH_EXPRESSIONS = translatedPrefixes; - } - - @Inject - private PathTranslator pathTranslator; - - private Interpolator interpolator; - - private RecursionInterceptor recursionInterceptor; - - // for testing. - protected AbstractStringBasedModelInterpolator(PathTranslator pathTranslator) { - this.pathTranslator = pathTranslator; - } - - protected AbstractStringBasedModelInterpolator() {} - - @Override - public Model interpolate(Model model, Map context) throws ModelInterpolationException { - return interpolate(model, context, true); - } - - /** - * Serialize the inbound Model instance to a StringWriter, perform the regex replacement to resolve - * POM expressions, then re-parse into the resolved Model instance. - *

- * NOTE: This will result in a different instance of Model being returned!!! - * - * @param model The inbound Model instance, to serialize and reference for expression resolution - * @param context The other context map to be used during resolution - * - * @return The resolved instance of the inbound Model. This is a different instance! - * - * @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead. - */ - @Deprecated - @Override - public Model interpolate(Model model, Map context, boolean strict) throws ModelInterpolationException { - Properties props = new Properties(); - props.putAll(context); - - return interpolate(model, null, new DefaultProjectBuilderConfiguration().setExecutionProperties(props), true); - } - - @Override - public Model interpolate(Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugEnabled) - throws ModelInterpolationException { - StringWriter sWriter = new StringWriter(1024); - - MavenStaxWriter writer = new MavenStaxWriter(); - try { - writer.write(sWriter, model.getDelegate()); - } catch (IOException | XMLStreamException e) { - throw new ModelInterpolationException("Cannot serialize project model for interpolation.", e); - } - - String serializedModel = sWriter.toString(); - serializedModel = interpolate(serializedModel, model, projectDir, config, debugEnabled); - - StringReader sReader = new StringReader(serializedModel); - - MavenStaxReader modelReader = new MavenStaxReader(); - try { - model = new Model(modelReader.read(sReader)); - } catch (XMLStreamException e) { - throw new ModelInterpolationException( - "Cannot read project model from interpolating filter of serialized version.", e); - } - - return model; - } - - /** - * Interpolates all expressions in the src parameter. - *

- * The algorithm used for each expression is: - *

    - *
  • If it starts with either "pom." or "project.", the expression is evaluated against the model.
  • - *
  • If the value is null, get the value from the context.
  • - *
  • If the value is null, but the context contains the expression, don't replace the expression string - * with the value, and continue to find other expressions.
  • - *
  • If the value is null, get it from the model properties.
  • - *
- */ - @Override - public String interpolate( - String src, Model model, final File projectDir, ProjectBuilderConfiguration config, boolean debug) - throws ModelInterpolationException { - try { - List valueSources = createValueSources(model, projectDir, config); - List postProcessors = createPostProcessors(model, projectDir, config); - - return interpolateInternal(src, valueSources, postProcessors, debug); - } finally { - interpolator.clearAnswers(); - } - } - - protected List createValueSources( - final Model model, final File projectDir, final ProjectBuilderConfiguration config) { - String timestampFormat = DEFAULT_BUILD_TIMESTAMP_FORMAT; - - Properties modelProperties = model.getProperties(); - if (modelProperties != null) { - timestampFormat = modelProperties.getProperty(BUILD_TIMESTAMP_FORMAT_PROPERTY, timestampFormat); - } - - ValueSource modelValueSource1 = new PrefixedObjectValueSource(PROJECT_PREFIXES, model, false); - ValueSource modelValueSource2 = new ObjectBasedValueSource(model); - - ValueSource basedirValueSource = new PrefixedValueSourceWrapper( - new AbstractValueSource(false) { - - @Override - public Object getValue(String expression) { - if (projectDir != null && "basedir".equals(expression)) { - return projectDir.getAbsolutePath(); - } - return null; - } - }, - PROJECT_PREFIXES, - true); - ValueSource baseUriValueSource = new PrefixedValueSourceWrapper( - new AbstractValueSource(false) { - - @Override - public Object getValue(String expression) { - if (projectDir != null && "baseUri".equals(expression)) { - return projectDir.getAbsoluteFile().toPath().toUri().toASCIIString(); - } - return null; - } - }, - PROJECT_PREFIXES, - false); - - List valueSources = new ArrayList<>(9); - - // NOTE: Order counts here! - valueSources.add(basedirValueSource); - valueSources.add(baseUriValueSource); - valueSources.add(new BuildTimestampValueSource(config.getBuildStartTime(), timestampFormat)); - valueSources.add(modelValueSource1); - valueSources.add(new MapBasedValueSource(config.getUserProperties())); - valueSources.add(new MapBasedValueSource(modelProperties)); - valueSources.add(new MapBasedValueSource(config.getExecutionProperties())); - valueSources.add(new AbstractValueSource(false) { - - @Override - public Object getValue(String expression) { - return config.getExecutionProperties().getProperty("env." + expression); - } - }); - valueSources.add(modelValueSource2); - - return valueSources; - } - - protected List createPostProcessors( - final Model model, final File projectDir, final ProjectBuilderConfiguration config) { - return Collections.singletonList(new PathTranslatingPostProcessor( - PROJECT_PREFIXES, TRANSLATED_PATH_EXPRESSIONS, projectDir, pathTranslator)); - } - - @SuppressWarnings("unchecked") - protected String interpolateInternal( - String src, List valueSources, List postProcessors, boolean debug) - throws ModelInterpolationException { - if (!src.contains("${")) { - return src; - } - - Logger logger = getLogger(); - - String result = src; - synchronized (this) { - for (ValueSource vs : valueSources) { - interpolator.addValueSource(vs); - } - - for (InterpolationPostProcessor postProcessor : postProcessors) { - interpolator.addPostProcessor(postProcessor); - } - - try { - try { - result = interpolator.interpolate(result, recursionInterceptor); - } catch (InterpolationException e) { - throw new ModelInterpolationException(e.getMessage(), e); - } - - if (debug) { - List feedback = interpolator.getFeedback(); - if (feedback != null && !feedback.isEmpty()) { - logger.debug("Maven encountered the following problems during initial POM interpolation:"); - - Object last = null; - for (Object next : feedback) { - if (next instanceof Throwable throwable) { - if (last == null) { - logger.debug("", throwable); - } else { - logger.debug(String.valueOf(last), throwable); - } - } else { - if (last != null) { - logger.debug(String.valueOf(last)); - } - - last = next; - } - } - - if (last != null) { - logger.debug(String.valueOf(last)); - } - } - } - - interpolator.clearFeedback(); - } finally { - for (ValueSource vs : valueSources) { - interpolator.removeValuesSource(vs); - } - - for (InterpolationPostProcessor postProcessor : postProcessors) { - interpolator.removePostProcessor(postProcessor); - } - } - } - - return result; - } - - protected RecursionInterceptor getRecursionInterceptor() { - return recursionInterceptor; - } - - protected void setRecursionInterceptor(RecursionInterceptor recursionInterceptor) { - this.recursionInterceptor = recursionInterceptor; - } - - protected abstract Interpolator createInterpolator(); - - @Override - public void initialize() throws InitializationException { - interpolator = createInterpolator(); - recursionInterceptor = new PrefixAwareRecursionInterceptor(PROJECT_PREFIXES); - } - - protected final Interpolator getInterpolator() { - return interpolator; - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/BuildTimestampValueSource.java b/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/BuildTimestampValueSource.java deleted file mode 100644 index 263f04ee957c..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/BuildTimestampValueSource.java +++ /dev/null @@ -1,56 +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.project.interpolation; - -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.codehaus.plexus.interpolation.AbstractValueSource; - -/** - * - */ -@Deprecated -public class BuildTimestampValueSource extends AbstractValueSource { - - private final Date startTime; - - private final String format; - - private String formattedDate; - - public BuildTimestampValueSource(Date startTime, String format) { - super(false); - this.startTime = startTime; - this.format = format; - } - - @Override - public Object getValue(String expression) { - if ("build.timestamp".equals(expression) || "maven.build.timestamp".equals(expression)) { - if (formattedDate == null && startTime != null) { - formattedDate = new SimpleDateFormat(format).format(startTime); - } - - return formattedDate; - } - - return null; - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/ModelInterpolationException.java b/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/ModelInterpolationException.java deleted file mode 100644 index 9200a094bf88..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/ModelInterpolationException.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.project.interpolation; - -/** - */ -@SuppressWarnings("serial") -@Deprecated -public class ModelInterpolationException extends Exception { - private String expression; - - private String originalMessage; - - public ModelInterpolationException(String message) { - super(message); - } - - public ModelInterpolationException(String message, Throwable cause) { - super(message, cause); - } - - public ModelInterpolationException(String expression, String message, Throwable cause) { - super("The POM expression: " + expression + " could not be evaluated. Reason: " + message, cause); - - this.expression = expression; - this.originalMessage = message; - } - - public ModelInterpolationException(String expression, String message) { - super("The POM expression: " + expression + " could not be evaluated. Reason: " + message); - - this.expression = expression; - this.originalMessage = message; - } - - public String getExpression() { - return expression; - } - - public String getOriginalMessage() { - return originalMessage; - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java b/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java deleted file mode 100644 index 42d4f1240741..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java +++ /dev/null @@ -1,55 +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.project.interpolation; - -import java.io.File; -import java.util.Map; - -import org.apache.maven.model.Model; -import org.apache.maven.project.ProjectBuilderConfiguration; - -/** - */ -@Deprecated -public interface ModelInterpolator { - String DEFAULT_BUILD_TIMESTAMP_FORMAT = "yyyyMMdd-HHmm"; - - String BUILD_TIMESTAMP_FORMAT_PROPERTY = "maven.build.timestamp.format"; - - String ROLE = ModelInterpolator.class.getName(); - - /** - * @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead. - */ - @Deprecated - Model interpolate(Model project, Map context) throws ModelInterpolationException; - - /** - * @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead. - */ - @Deprecated - Model interpolate(Model model, Map context, boolean strict) throws ModelInterpolationException; - - Model interpolate(Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugEnabled) - throws ModelInterpolationException; - - String interpolate( - String src, Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugEnabled) - throws ModelInterpolationException; -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java b/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java deleted file mode 100644 index 255826d3ea87..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java +++ /dev/null @@ -1,60 +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.project.interpolation; - -import java.io.File; -import java.util.List; - -import org.apache.maven.project.path.PathTranslator; -import org.codehaus.plexus.interpolation.InterpolationPostProcessor; -import org.codehaus.plexus.interpolation.util.ValueSourceUtils; - -/** - * - */ -@Deprecated -public class PathTranslatingPostProcessor implements InterpolationPostProcessor { - - private final List unprefixedPathKeys; - private final File projectDir; - private final PathTranslator pathTranslator; - private final List expressionPrefixes; - - public PathTranslatingPostProcessor( - List expressionPrefixes, - List unprefixedPathKeys, - File projectDir, - PathTranslator pathTranslator) { - this.expressionPrefixes = expressionPrefixes; - this.unprefixedPathKeys = unprefixedPathKeys; - this.projectDir = projectDir; - this.pathTranslator = pathTranslator; - } - - @Override - public Object execute(String expression, Object value) { - expression = ValueSourceUtils.trimPrefix(expression, expressionPrefixes, true); - - if (projectDir != null && value != null && unprefixedPathKeys.contains(expression)) { - return pathTranslator.alignToBaseDirectory(String.valueOf(value), projectDir); - } - - return value; - } -} diff --git a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java b/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java deleted file mode 100644 index c7cea8d13b79..000000000000 --- a/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/StringSearchModelInterpolator.java +++ /dev/null @@ -1,303 +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.project.interpolation; - -import javax.inject.Named; -import javax.inject.Singleton; - -import java.io.File; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; - -import org.apache.maven.model.Model; -import org.apache.maven.project.ProjectBuilderConfiguration; -import org.apache.maven.project.path.PathTranslator; -import org.codehaus.plexus.interpolation.InterpolationPostProcessor; -import org.codehaus.plexus.interpolation.Interpolator; -import org.codehaus.plexus.interpolation.StringSearchInterpolator; -import org.codehaus.plexus.interpolation.ValueSource; -import org.codehaus.plexus.logging.Logger; - -/** - * StringSearchModelInterpolator - */ -@Deprecated -@Named -@Singleton -public class StringSearchModelInterpolator extends AbstractStringBasedModelInterpolator { - - private static final Map, Field[]> FIELDS_BY_CLASS = new WeakHashMap<>(); - private static final Map, Boolean> PRIMITIVE_BY_CLASS = new WeakHashMap<>(); - - public StringSearchModelInterpolator() {} - - public StringSearchModelInterpolator(PathTranslator pathTranslator) { - super(pathTranslator); - } - - @Override - public Model interpolate(Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugEnabled) - throws ModelInterpolationException { - interpolateObject(model, model, projectDir, config, debugEnabled); - - return model; - } - - protected void interpolateObject( - Object obj, Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugEnabled) - throws ModelInterpolationException { - try { - List valueSources = createValueSources(model, projectDir, config); - List postProcessors = createPostProcessors(model, projectDir, config); - - InterpolateObjectAction action = - new InterpolateObjectAction(obj, valueSources, postProcessors, debugEnabled, this, getLogger()); - - ModelInterpolationException error = AccessController.doPrivileged(action); - - if (error != null) { - throw error; - } - } finally { - getInterpolator().clearAnswers(); - } - } - - @Override - protected Interpolator createInterpolator() { - StringSearchInterpolator interpolator = new StringSearchInterpolator(); - interpolator.setCacheAnswers(true); - - return interpolator; - } - - private static final class InterpolateObjectAction implements PrivilegedAction { - - private final boolean debugEnabled; - private final LinkedList interpolationTargets; - private final StringSearchModelInterpolator modelInterpolator; - private final Logger logger; - private final List valueSources; - private final List postProcessors; - - InterpolateObjectAction( - Object target, - List valueSources, - List postProcessors, - boolean debugEnabled, - StringSearchModelInterpolator modelInterpolator, - Logger logger) { - this.valueSources = valueSources; - this.postProcessors = postProcessors; - this.debugEnabled = debugEnabled; - - this.interpolationTargets = new LinkedList<>(); - interpolationTargets.add(target); - - this.modelInterpolator = modelInterpolator; - this.logger = logger; - } - - @Override - public ModelInterpolationException run() { - while (!interpolationTargets.isEmpty()) { - Object obj = interpolationTargets.removeFirst(); - - try { - traverseObjectWithParents(obj.getClass(), obj); - } catch (ModelInterpolationException e) { - return e; - } - } - - return null; - } - - @SuppressWarnings({"unchecked", "checkstyle:methodlength"}) - private void traverseObjectWithParents(Class cls, Object target) throws ModelInterpolationException { - if (cls == null) { - return; - } - - if (cls.isArray()) { - evaluateArray(target); - } else if (isQualifiedForInterpolation(cls)) { - Field[] fields = FIELDS_BY_CLASS.computeIfAbsent(cls, k -> cls.getDeclaredFields()); - - for (Field field : fields) { - Class type = field.getType(); - if (isQualifiedForInterpolation(field, type)) { - boolean isAccessible = field.isAccessible(); - field.setAccessible(true); - try { - try { - if (String.class == type) { - String value = (String) field.get(target); - if (value != null) { - String interpolated = modelInterpolator.interpolateInternal( - value, valueSources, postProcessors, debugEnabled); - - if (!interpolated.equals(value)) { - field.set(target, interpolated); - } - } - } else if (Collection.class.isAssignableFrom(type)) { - Collection c = (Collection) field.get(target); - if (c != null && !c.isEmpty()) { - List originalValues = new ArrayList<>(c); - try { - c.clear(); - } catch (UnsupportedOperationException e) { - if (debugEnabled && logger != null) { - logger.debug("Skipping interpolation of field: " + field + " in: " - + cls.getName() - + "; it is an unmodifiable collection."); - } - continue; - } - - for (Object value : originalValues) { - if (value != null) { - if (String.class == value.getClass()) { - String interpolated = modelInterpolator.interpolateInternal( - (String) value, valueSources, postProcessors, debugEnabled); - - if (!interpolated.equals(value)) { - c.add(interpolated); - } else { - c.add(value); - } - } else { - c.add(value); - if (value.getClass().isArray()) { - evaluateArray(value); - } else { - interpolationTargets.add(value); - } - } - } else { - // add the null back in...not sure what else to do... - c.add(value); - } - } - } - } else if (Map.class.isAssignableFrom(type)) { - Map m = (Map) field.get(target); - if (m != null && !m.isEmpty()) { - for (Map.Entry entry : m.entrySet()) { - Object value = entry.getValue(); - - if (value != null) { - if (String.class == value.getClass()) { - String interpolated = modelInterpolator.interpolateInternal( - (String) value, valueSources, postProcessors, debugEnabled); - - if (!interpolated.equals(value)) { - try { - entry.setValue(interpolated); - } catch (UnsupportedOperationException e) { - if (debugEnabled && logger != null) { - logger.debug("Skipping interpolation of field: " + field - + " (key: " + entry.getKey() + ") in: " - + cls.getName() - + "; it is an unmodifiable collection."); - } - } - } - } else { - if (value.getClass().isArray()) { - evaluateArray(value); - } else { - interpolationTargets.add(value); - } - } - } - } - } - } else { - Object value = field.get(target); - if (value != null) { - if (field.getType().isArray()) { - evaluateArray(value); - } else { - interpolationTargets.add(value); - } - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new ModelInterpolationException( - "Failed to interpolate field: " + field + " on class: " + cls.getName(), e); - } - } finally { - field.setAccessible(isAccessible); - } - } - } - - traverseObjectWithParents(cls.getSuperclass(), target); - } - } - - private boolean isQualifiedForInterpolation(Class cls) { - return !cls.getPackage().getName().startsWith("java") - && !cls.getPackage().getName().startsWith("sun.nio.fs") - // org.apache.maven.api.model.InputLocation can be self-referencing - && !cls.getName().equals("org.apache.maven.api.model.InputLocation"); - } - - private boolean isQualifiedForInterpolation(Field field, Class fieldType) { - if (!PRIMITIVE_BY_CLASS.containsKey(fieldType)) { - PRIMITIVE_BY_CLASS.put(fieldType, fieldType.isPrimitive()); - } - - if (PRIMITIVE_BY_CLASS.get(fieldType)) { - return false; - } - - return !"parent".equals(field.getName()); - } - - private void evaluateArray(Object target) throws ModelInterpolationException { - int len = Array.getLength(target); - for (int i = 0; i < len; i++) { - Object value = Array.get(target, i); - if (value != null) { - if (String.class == value.getClass()) { - String interpolated = modelInterpolator.interpolateInternal( - (String) value, valueSources, postProcessors, debugEnabled); - - if (!interpolated.equals(value)) { - Array.set(target, i, interpolated); - } - } else { - interpolationTargets.add(value); - } - } - } - } - } -} diff --git a/compat/maven-compat/src/test/java/org/apache/maven/project/interpolation/StringSearchModelInterpolatorTest.java b/compat/maven-compat/src/test/java/org/apache/maven/project/interpolation/StringSearchModelInterpolatorTest.java deleted file mode 100644 index b5c1f6418862..000000000000 --- a/compat/maven-compat/src/test/java/org/apache/maven/project/interpolation/StringSearchModelInterpolatorTest.java +++ /dev/null @@ -1,41 +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.project.interpolation; - -import java.util.Map; - -import org.apache.maven.api.model.InputLocation; -import org.apache.maven.api.model.InputSource; -import org.apache.maven.api.model.Model; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; -import org.junit.jupiter.api.Test; - -class StringSearchModelInterpolatorTest { - - @Test - void interpolate() throws ModelInterpolationException, InitializationException { - Model model = Model.newBuilder() - .groupId("group") - .location("groupId", InputLocation.of(InputSource.of("model", null))) - .build(); - StringSearchModelInterpolator interpolator = new StringSearchModelInterpolator(); - interpolator.initialize(); - interpolator.interpolate(new org.apache.maven.model.Model(model), Map.of()); - } -} diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5445LegacyStringSearchModelInterpolatorTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5445LegacyStringSearchModelInterpolatorTest.java deleted file mode 100644 index b49dd07568b5..000000000000 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5445LegacyStringSearchModelInterpolatorTest.java +++ /dev/null @@ -1,55 +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.it; - -import java.nio.file.Path; - -import org.junit.jupiter.api.Test; - -/** - * This is a test set for MNG-5445. - */ -public class MavenITmng5445LegacyStringSearchModelInterpolatorTest extends AbstractMavenIntegrationTestCase { - - /** - * Verify that the legacy StringSearchModelInterpolator has its PathTranslator injected. - * - * @throws Exception in case of failure - */ - @Test - public void testit() throws Exception { - Path testDir = extractResources("mng-5445"); - - // First, build the test plugin - Verifier verifier = newVerifier(testDir.resolve("maven-it-plugin-model-interpolation")); - verifier.setAutoclean(false); - verifier.deleteDirectory("target"); - verifier.addCliArgument("install"); - verifier.execute(); - verifier.verifyErrorFreeLog(); - - // Then, run the test project that uses the plugin - verifier = newVerifier(testDir); - verifier.setAutoclean(false); - verifier.deleteDirectory("target"); - verifier.addCliArgument("validate"); - verifier.execute(); - verifier.verifyErrorFreeLog(); - } -} diff --git a/its/core-it-suite/src/test/resources/mng-3652/test-plugin/src/main/java/org/apache/maven/its/mng3652/MyMojo.java b/its/core-it-suite/src/test/resources/mng-3652/test-plugin/src/main/java/org/apache/maven/its/mng3652/MyMojo.java index 72bc14d3839d..c3529eaacb99 100644 --- a/its/core-it-suite/src/test/resources/mng-3652/test-plugin/src/main/java/org/apache/maven/its/mng3652/MyMojo.java +++ b/its/core-it-suite/src/test/resources/mng-3652/test-plugin/src/main/java/org/apache/maven/its/mng3652/MyMojo.java @@ -32,12 +32,12 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.rtinfo.RuntimeInformation; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; @@ -135,7 +135,7 @@ public void execute() throws MojoExecutionException { touchFile.getParentFile().mkdirs(); w = new FileWriter(touchFile); - w.write(runtimeInformation.getApplicationVersion().toString()); + w.write(runtimeInformation.getMavenVersion()); w.write(LS); w.write(System.getProperty("java.version")); w.write(LS); diff --git a/its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/pom.xml b/its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/pom.xml deleted file mode 100644 index 559e661013cb..000000000000 --- a/its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/pom.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - 4.0.0 - - org.apache.maven.its.plugins - - maven-it-plugin-model-interpolation - 2.1-SNAPSHOT - maven-plugin - - Maven IT Plugin :: Model Interpolation - 2013 - - - 8 - 8 - UTF-8 - - - - org.apache.maven - maven-plugin-api - 3.9.0 - provided - - - org.apache.maven.plugin-tools - maven-plugin-annotations - 3.15.1 - provided - - - org.apache.maven - maven-core - 3.9.0 - provided - - - org.apache.maven - maven-compat - 3.9.0 - provided - - - - org.apache.maven.its - maven-it-helper - ${project.version} - - - org.apache.maven - maven-artifact - - - org.apache.maven.shared - maven-verifier - - - junit - junit - - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - 3.15.1 - - model-interpolation - - - - - diff --git a/its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/src/main/java/org/apache/maven/plugin/coreit/PathInterpolationMojo.java b/its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/src/main/java/org/apache/maven/plugin/coreit/PathInterpolationMojo.java deleted file mode 100644 index 892b7cde5755..000000000000 --- a/its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/src/main/java/org/apache/maven/plugin/coreit/PathInterpolationMojo.java +++ /dev/null @@ -1,63 +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.plugin.coreit; - -import java.util.Properties; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.DefaultProjectBuilderConfiguration; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.interpolation.ModelInterpolationException; -import org.apache.maven.project.interpolation.ModelInterpolator; - -/** - */ -@Mojo(name = "path-interpolation", defaultPhase = LifecyclePhase.VALIDATE) -public class PathInterpolationMojo extends AbstractMojo { - /** - * The model interpolator - */ - @Component - private ModelInterpolator modelInterpolator; - - /** - * The current Maven project. - */ - @Parameter(defaultValue = "${project}") - private MavenProject project; - - public void execute() throws MojoExecutionException { - try { - Properties props = project.getProperties(); - - modelInterpolator.interpolate( - project.getOriginalModel(), - project.getBasedir(), - new DefaultProjectBuilderConfiguration().setExecutionProperties(props), - true); - } catch (ModelInterpolationException e) { - throw new MojoExecutionException(e.getMessage(), e); - } - } -} diff --git a/its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/src/site/site.xml b/its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/src/site/site.xml deleted file mode 100644 index d875e7029292..000000000000 --- a/its/core-it-suite/src/test/resources/mng-5445/maven-it-plugin-model-interpolation/src/site/site.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - diff --git a/its/core-it-suite/src/test/resources/mng-5445/pom.xml b/its/core-it-suite/src/test/resources/mng-5445/pom.xml deleted file mode 100644 index b0b192568d69..000000000000 --- a/its/core-it-suite/src/test/resources/mng-5445/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - 4.0.0 - - org.apache.maven.its.mng5445 - mng5445-it - 0.0.1-SNAPSHOT - - Test StringSearchModelInterpolator with path-based properties - http://maven.apache.org - - - UTF-8 - ${project.build.sourceDirectory}/foo - - - - - - org.apache.maven.its.plugins - maven-it-plugin-model-interpolation - 2.1-SNAPSHOT - - - - path-interpolation - - - - - - src - - -