You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/04/08 19:23:04 UTC
[GitHub] [maven] cstamas opened a new pull request, #712: Use of the propsed ArtifactTransformer in Maven
cstamas opened a new pull request, #712:
URL: https://github.com/apache/maven/pull/712
To implement Consumer POM. There are a lot of shortcuts but
the code is not worse that master had (left few TODOs).
All the ITs locally pass with this build.
To work, requires resolver artifact-transformer branch.
https://github.com/apache/maven-resolver/pull/162
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] rfscholte commented on a diff in pull request #712: Provide file transformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
rfscholte commented on code in PR #712:
URL: https://github.com/apache/maven/pull/712#discussion_r847044265
##########
maven-core/src/main/java/org/apache/maven/artifact/transform/ConsumerPomTransformer.java:
##########
@@ -0,0 +1,140 @@
+package org.apache.maven.artifact.transform;
+
+/*
+ * 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.
+ */
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.TransformerContext;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM install and deploy transformer.
+ */
+@Named( ConsumerPomTransformer.NAME )
+@Singleton
+public class ConsumerPomTransformer implements InstallRequestTransformer, DeployRequestTransformer
Review Comment:
One of my concerns was regarding how open this should be, as it is very powerful. At first I don't want other custom components to interfere and keep Maven in full control.
##########
maven-core/src/main/java/org/apache/maven/artifact/transform/ConsumerPomTransformer.java:
##########
@@ -0,0 +1,140 @@
+package org.apache.maven.artifact.transform;
+
+/*
+ * 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.
+ */
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.TransformerContext;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM install and deploy transformer.
+ */
+@Named( ConsumerPomTransformer.NAME )
+@Singleton
+public class ConsumerPomTransformer implements InstallRequestTransformer, DeployRequestTransformer
+{
+ public static final String NAME = "consumer-pom";
+
+ private final Provider<MavenSession> mavenSessionProvider;
+
+ @Inject
+ public ConsumerPomTransformer( Provider<MavenSession> mavenSessionProvider )
+ {
+ this.mavenSessionProvider = mavenSessionProvider;
+ }
+
+ @Override
+ public DeployRequest transformDeployRequest( RepositorySystemSession session,
+ DeployRequest deployRequest )
+ {
+ MavenSession mavenSession = mavenSessionProvider.get();
+ if ( !Features.buildConsumer( mavenSession.getUserProperties() ).isActive() )
+ {
+ return deployRequest;
+ }
+ return deployRequest.setArtifacts( transformArtifacts( mavenSession, deployRequest.getArtifacts() ) );
+ }
+
+ @Override
+ public InstallRequest transformInstallRequest( RepositorySystemSession session,
+ InstallRequest installRequest )
+ {
+ MavenSession mavenSession = mavenSessionProvider.get();
+ if ( !Features.buildConsumer( mavenSession.getUserProperties() ).isActive() )
+ {
+ return installRequest;
+ }
+ return installRequest.setArtifacts( transformArtifacts( mavenSession, installRequest.getArtifacts() ) );
+ }
+
+ private Collection<Artifact> transformArtifacts( MavenSession mavenSession, Collection<Artifact> artifacts )
+ {
+ TransformerContext context = (TransformerContext) mavenSession
+ .getRepositorySession().getData().get( TransformerContext.KEY );
+ if ( context == null )
+ {
+ return artifacts;
+ }
+ ArrayList<Artifact> result = new ArrayList<>( artifacts.size() );
+ for ( Artifact artifact : artifacts )
+ {
+ if ( "pom".equals( artifact.getExtension() ) )
+ {
+ Path buildOutputDirectory = Paths.get(
+ mavenSession.getCurrentProject().getBuild().getDirectory() );
+ Path originalPom = artifact.getFile().toPath();
+ Path transformedPom = buildOutputDirectory.resolve( NAME + ".xml" );
+ try
+ {
+ FileTime originalPomTs = Files.getLastModifiedTime( originalPom );
+ FileTime transformedPomTs = Files.isRegularFile( transformedPom )
+ ? Files.getLastModifiedTime( transformedPom ) : null;
+
+ if ( !originalPomTs.equals( transformedPomTs ) )
+ {
+ // save it: either does not exist or TS differ
+ Files.createDirectories( transformedPom.getParent() );
+ try ( InputStream inputStream = new ConsumerModelSourceTransformer()
+ .transform( originalPom, context ) )
+ {
+ Files.copy( inputStream, transformedPom );
Review Comment:
One of my personal goals was preventing temporary files, as it opens a backdoor to rewrite the pom.
And I don't think there should be a need for it: passing the inputstream should be possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] slawekjaranowski commented on pull request #712: Provide file transformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on PR #712:
URL: https://github.com/apache/maven/pull/712#issuecomment-1093910484
I see another issue `TransformerContext` is used by `ConsumerModelSourceTransformer` but leak to other Maven core components.
IMHO eache Transformer component implementation should be independent of internal core implementation.
But it can be other issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] cstamas commented on pull request #712: Use of the proposed new transformer API in Maven
Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #712:
URL: https://github.com/apache/maven/pull/712#issuecomment-1093838217
@slawekjaranowski just FYI https://github.com/apache/maven-resolver/commit/1c79c4f8b6573e9693f4ae61c14bff17755aa32d
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] rfscholte commented on a diff in pull request #712: Provide file transformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
rfscholte commented on code in PR #712:
URL: https://github.com/apache/maven/pull/712#discussion_r847206558
##########
maven-core/src/main/java/org/apache/maven/artifact/transform/ConsumerPomTransformer.java:
##########
@@ -0,0 +1,140 @@
+package org.apache.maven.artifact.transform;
+
+/*
+ * 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.
+ */
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.TransformerContext;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM install and deploy transformer.
+ */
+@Named( ConsumerPomTransformer.NAME )
+@Singleton
+public class ConsumerPomTransformer implements InstallRequestTransformer, DeployRequestTransformer
+{
+ public static final String NAME = "consumer-pom";
+
+ private final Provider<MavenSession> mavenSessionProvider;
+
+ @Inject
+ public ConsumerPomTransformer( Provider<MavenSession> mavenSessionProvider )
+ {
+ this.mavenSessionProvider = mavenSessionProvider;
+ }
+
+ @Override
+ public DeployRequest transformDeployRequest( RepositorySystemSession session,
+ DeployRequest deployRequest )
+ {
+ MavenSession mavenSession = mavenSessionProvider.get();
+ if ( !Features.buildConsumer( mavenSession.getUserProperties() ).isActive() )
+ {
+ return deployRequest;
+ }
+ return deployRequest.setArtifacts( transformArtifacts( mavenSession, deployRequest.getArtifacts() ) );
+ }
+
+ @Override
+ public InstallRequest transformInstallRequest( RepositorySystemSession session,
+ InstallRequest installRequest )
+ {
+ MavenSession mavenSession = mavenSessionProvider.get();
+ if ( !Features.buildConsumer( mavenSession.getUserProperties() ).isActive() )
+ {
+ return installRequest;
+ }
+ return installRequest.setArtifacts( transformArtifacts( mavenSession, installRequest.getArtifacts() ) );
+ }
+
+ private Collection<Artifact> transformArtifacts( MavenSession mavenSession, Collection<Artifact> artifacts )
+ {
+ TransformerContext context = (TransformerContext) mavenSession
+ .getRepositorySession().getData().get( TransformerContext.KEY );
+ if ( context == null )
+ {
+ return artifacts;
+ }
+ ArrayList<Artifact> result = new ArrayList<>( artifacts.size() );
+ for ( Artifact artifact : artifacts )
+ {
+ if ( "pom".equals( artifact.getExtension() ) )
+ {
+ Path buildOutputDirectory = Paths.get(
+ mavenSession.getCurrentProject().getBuild().getDirectory() );
+ Path originalPom = artifact.getFile().toPath();
+ Path transformedPom = buildOutputDirectory.resolve( NAME + ".xml" );
+ try
+ {
+ FileTime originalPomTs = Files.getLastModifiedTime( originalPom );
+ FileTime transformedPomTs = Files.isRegularFile( transformedPom )
+ ? Files.getLastModifiedTime( transformedPom ) : null;
+
+ if ( !originalPomTs.equals( transformedPomTs ) )
+ {
+ // save it: either does not exist or TS differ
+ Files.createDirectories( transformedPom.getParent() );
+ try ( InputStream inputStream = new ConsumerModelSourceTransformer()
+ .transform( originalPom, context ) )
+ {
+ Files.copy( inputStream, transformedPom );
Review Comment:
Overall I agree and main thing is that the concept of build/consumer keeps working.
However, I think it is worth reconsidering if resolver is really about Files and not InputStreams. With the architecture of Maven 2+3 it makes sense to use File as the base, but IMO with Maven 4+5 an InputStream would make more sense. And as a bonus I would expect less IO which should result in better performance as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] slawekjaranowski commented on pull request #712: Use of the proposed new transformer API in Maven
Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on PR #712:
URL: https://github.com/apache/maven/pull/712#issuecomment-1093837719
Will be appreciate show example how plugin can add new transformers like signers.
I use transformers in sign-m-p for build signatures.
https://github.com/s4u/sign-maven-plugin/blob/master/src/main/java/org/simplify4u/plugins/sign/ArtifactSigner40.java
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] cstamas commented on a diff in pull request #712: Use of the propsed ArtifactTransformer in Maven
Posted by GitBox <gi...@apache.org>.
cstamas commented on code in PR #712:
URL: https://github.com/apache/maven/pull/712#discussion_r846604072
##########
maven-core/src/main/java/org/apache/maven/internal/aether/ConsumerPomArtifactTransformer.java:
##########
@@ -0,0 +1,94 @@
+package org.apache.maven.internal.aether;
+
+/*
+ * 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.
+ */
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.building.TransformerContext;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.transform.ArtifactTransformer;
+
+@Named( ConsumerPomArtifactTransformer.NAME )
+@Singleton
+public class ConsumerPomArtifactTransformer implements ArtifactTransformer
+{
+ public static final String NAME = "consumer-pom";
+
+ private final Provider<MavenSession> mavenSessionProvider;
+
+ @Inject
+ public ConsumerPomArtifactTransformer( Provider<MavenSession> mavenSessionProvider )
+ {
+ this.mavenSessionProvider = mavenSessionProvider;
+ }
+
+ @Override
+ public Collection<Artifact> transformArtifact( Artifact artifact )
+ {
+ MavenSession mavenSession = mavenSessionProvider.get();
+ TransformerContext context = (TransformerContext) mavenSession
+ .getRepositorySession().getData().get( TransformerContext.KEY );
+ if ( "pom".equals( artifact.getExtension() ) && context != null )
+ {
+ // TODO: fix this, make it target rather
+ Path buildOutputDirectory = Paths.get(
+ mavenSession.getCurrentProject().getBuild().getTestOutputDirectory() );
Review Comment:
is wip, nvm
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] slawekjaranowski commented on a diff in pull request #712: Use of the proposed new transformer API in Maven
Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on code in PR #712:
URL: https://github.com/apache/maven/pull/712#discussion_r846606690
##########
maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java:
##########
@@ -261,9 +261,37 @@ else if ( request.isUpdateSnapshots() )
mavenRepositorySystem.injectProxy( session, request.getPluginArtifactRepositories() );
mavenRepositorySystem.injectAuthentication( session, request.getPluginArtifactRepositories() );
- if ( Features.buildConsumer( request.getUserProperties() ).isActive() )
+ if ( !installRequestTransformers.isEmpty() )
+ {
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "Applying install request transformers (shown in order):" );
+ for ( InstallRequestTransformer transformer : installRequestTransformers )
+ {
+ logger.debug( " * {}", transformer.getClass() );
+ }
+ logger.debug( "" );
+ }
+ session.getData().set(
+ InstallRequestTransformer.KEY,
+ new ChainedInstallRequestTransformer( installRequestTransformers )
+ );
+ }
+ if ( !deployRequestTransformers.isEmpty() )
{
- session.setFileTransformerManager( a -> getTransformersForArtifact( a, session.getData() ) );
Review Comment:
do we remove both `setFileTransformerManager` and `getFileTransformerManager` from `session`?
if not set what return get method?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] slawekjaranowski commented on pull request #712: Provide file transformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on PR #712:
URL: https://github.com/apache/maven/pull/712#issuecomment-1093884007
We will have `InstallRequestTransformer` and `DeployRequestTransformer` so when I implement different component for it
will it possible that I will have different list of installed and deployed artifacts?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] cstamas closed pull request #712: [MNG-7456] Provide FileTransformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
cstamas closed pull request #712: [MNG-7456] Provide FileTransformer API replacement in Maven
URL: https://github.com/apache/maven/pull/712
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] cstamas commented on a diff in pull request #712: Provide file transformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
cstamas commented on code in PR #712:
URL: https://github.com/apache/maven/pull/712#discussion_r846613885
##########
maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java:
##########
@@ -261,9 +261,37 @@ else if ( request.isUpdateSnapshots() )
mavenRepositorySystem.injectProxy( session, request.getPluginArtifactRepositories() );
mavenRepositorySystem.injectAuthentication( session, request.getPluginArtifactRepositories() );
- if ( Features.buildConsumer( request.getUserProperties() ).isActive() )
+ if ( !installRequestTransformers.isEmpty() )
+ {
+ if ( logger.isDebugEnabled() )
+ {
+ logger.debug( "Applying install request transformers (shown in order):" );
+ for ( InstallRequestTransformer transformer : installRequestTransformers )
+ {
+ logger.debug( " * {}", transformer.getClass() );
+ }
+ logger.debug( "" );
+ }
+ session.getData().set(
+ InstallRequestTransformer.KEY,
+ new ChainedInstallRequestTransformer( installRequestTransformers )
+ );
+ }
+ if ( !deployRequestTransformers.isEmpty() )
{
- session.setFileTransformerManager( a -> getTransformersForArtifact( a, session.getData() ) );
Review Comment:
Do not use FileTransformer API anymore, in short. If this get's accepted, you will want to implement DeployRequestTransformer component... but let's go baby steps first, and make sure this would work for you too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] cstamas commented on pull request #712: Provide file transformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #712:
URL: https://github.com/apache/maven/pull/712#issuecomment-1093981282
> We will have `InstallRequestTransformer` and `DeployRequestTransformer` so when I implement different component for it will it possible that I will have different list of installed and deployed artifacts?
That's right and true even today, yes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] cstamas commented on pull request #712: [MNG-7456] Provide FileTransformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #712:
URL: https://github.com/apache/maven/pull/712#issuecomment-1346067858
Superseded by https://github.com/apache/maven/pull/907
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] cstamas commented on pull request #712: Use of the proposed new transformer API in Maven
Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #712:
URL: https://github.com/apache/maven/pull/712#issuecomment-1093835106
@slawekjaranowski so, this is new proposal. The interesting thing is that now we can define a "chain" of transformers, separately, for install and for deploy. The order of transformers is currently defined by SISU only (so sisu component ordering applies, as to everything in Maven, see https://www.eclipse.org/lists/sisu-users/msg00144.html, we can later refine this if needed).
So, the point is, that now one can define for deploy only:
* consumer-pom - transforms installed/deployed pom to consumer pom
* signer - signs artifacts
* CI build provenance - attaches some extra descriptor artifact
* etc
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] cstamas commented on a diff in pull request #712: Provide file transformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
cstamas commented on code in PR #712:
URL: https://github.com/apache/maven/pull/712#discussion_r847184452
##########
maven-core/src/main/java/org/apache/maven/artifact/transform/ConsumerPomTransformer.java:
##########
@@ -0,0 +1,140 @@
+package org.apache.maven.artifact.transform;
+
+/*
+ * 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.
+ */
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.TransformerContext;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM install and deploy transformer.
+ */
+@Named( ConsumerPomTransformer.NAME )
+@Singleton
+public class ConsumerPomTransformer implements InstallRequestTransformer, DeployRequestTransformer
+{
+ public static final String NAME = "consumer-pom";
+
+ private final Provider<MavenSession> mavenSessionProvider;
+
+ @Inject
+ public ConsumerPomTransformer( Provider<MavenSession> mavenSessionProvider )
+ {
+ this.mavenSessionProvider = mavenSessionProvider;
+ }
+
+ @Override
+ public DeployRequest transformDeployRequest( RepositorySystemSession session,
+ DeployRequest deployRequest )
+ {
+ MavenSession mavenSession = mavenSessionProvider.get();
+ if ( !Features.buildConsumer( mavenSession.getUserProperties() ).isActive() )
+ {
+ return deployRequest;
+ }
+ return deployRequest.setArtifacts( transformArtifacts( mavenSession, deployRequest.getArtifacts() ) );
+ }
+
+ @Override
+ public InstallRequest transformInstallRequest( RepositorySystemSession session,
+ InstallRequest installRequest )
+ {
+ MavenSession mavenSession = mavenSessionProvider.get();
+ if ( !Features.buildConsumer( mavenSession.getUserProperties() ).isActive() )
+ {
+ return installRequest;
+ }
+ return installRequest.setArtifacts( transformArtifacts( mavenSession, installRequest.getArtifacts() ) );
+ }
+
+ private Collection<Artifact> transformArtifacts( MavenSession mavenSession, Collection<Artifact> artifacts )
+ {
+ TransformerContext context = (TransformerContext) mavenSession
+ .getRepositorySession().getData().get( TransformerContext.KEY );
+ if ( context == null )
+ {
+ return artifacts;
+ }
+ ArrayList<Artifact> result = new ArrayList<>( artifacts.size() );
+ for ( Artifact artifact : artifacts )
+ {
+ if ( "pom".equals( artifact.getExtension() ) )
+ {
+ Path buildOutputDirectory = Paths.get(
+ mavenSession.getCurrentProject().getBuild().getDirectory() );
+ Path originalPom = artifact.getFile().toPath();
+ Path transformedPom = buildOutputDirectory.resolve( NAME + ".xml" );
+ try
+ {
+ FileTime originalPomTs = Files.getLastModifiedTime( originalPom );
+ FileTime transformedPomTs = Files.isRegularFile( transformedPom )
+ ? Files.getLastModifiedTime( transformedPom ) : null;
+
+ if ( !originalPomTs.equals( transformedPomTs ) )
+ {
+ // save it: either does not exist or TS differ
+ Files.createDirectories( transformedPom.getParent() );
+ try ( InputStream inputStream = new ConsumerModelSourceTransformer()
+ .transform( originalPom, context ) )
+ {
+ Files.copy( inputStream, transformedPom );
Review Comment:
Am unsure what backdoor would be solved by not using temporary file. True, here am using component name, but the file name could be randomized instead, and effectively it would prevent any code to tamper with it.
Resolver is all about `java.io.Files`, so no, resolver does not allow passing over InputStream. Moreover, misuse of it's internal APIs (like it happened with FileTransformer), where `org.eclipse.aether.spi.connector.transport.PutTask#dataBytes` (meant and used for checksums only, by resolver itself) was used to transfer rewritten POM is just IMHO merely wrong: it misuses resolver API to prevent Maven API misuse....?
This whole "do not save the file" to me looks like some sort of "premature optimization" parallel: it is assumed, that not saving transformed POM prevents some sort of backdoor, that we are actually not even sure about what it is.... Let's solve problems when we actually hit them IMHO.
Finally, IMHO all this feature is really Maven concern, not Resolver concern. And true, maven-3.x does not have any "callback" to transform "just in time" when m-install-p or m-deploy-p calls (directly) into resolver, but IMHO this is much cleaner solution, and you are using proper APIs just to "swap out" (replace) the artifact about to be deploy to another one. Also, it works, as ITs are showing. Hence, I think this should be solved within realm of Maven, and not have Resolver involved into this at all.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] slawekjaranowski commented on pull request #712: Provide file transformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on PR #712:
URL: https://github.com/apache/maven/pull/712#issuecomment-1093931583
Another idea maybe we should have dedicated transformers for poms where result should be visible in reactor for other modules - m-shade-p case.
And another transformers for rest of artifacts - where result can be consumed once by install and deploy phase.
Now we do the same transformations twice.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] slawekjaranowski commented on a diff in pull request #712: Use of the propsed ArtifactTransformer in Maven
Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on code in PR #712:
URL: https://github.com/apache/maven/pull/712#discussion_r846466166
##########
maven-core/src/main/java/org/apache/maven/internal/aether/ConsumerPomArtifactTransformer.java:
##########
@@ -0,0 +1,94 @@
+package org.apache.maven.internal.aether;
+
+/*
+ * 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.
+ */
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.building.TransformerContext;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.transform.ArtifactTransformer;
+
+@Named( ConsumerPomArtifactTransformer.NAME )
+@Singleton
+public class ConsumerPomArtifactTransformer implements ArtifactTransformer
+{
+ public static final String NAME = "consumer-pom";
+
+ private final Provider<MavenSession> mavenSessionProvider;
+
+ @Inject
+ public ConsumerPomArtifactTransformer( Provider<MavenSession> mavenSessionProvider )
+ {
+ this.mavenSessionProvider = mavenSessionProvider;
+ }
+
+ @Override
+ public Collection<Artifact> transformArtifact( Artifact artifact )
+ {
+ MavenSession mavenSession = mavenSessionProvider.get();
+ TransformerContext context = (TransformerContext) mavenSession
+ .getRepositorySession().getData().get( TransformerContext.KEY );
+ if ( "pom".equals( artifact.getExtension() ) && context != null )
+ {
+ // TODO: fix this, make it target rather
+ Path buildOutputDirectory = Paths.get(
+ mavenSession.getCurrentProject().getBuild().getTestOutputDirectory() );
Review Comment:
getTestOutputDirectory - ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] cstamas commented on a diff in pull request #712: Provide file transformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
cstamas commented on code in PR #712:
URL: https://github.com/apache/maven/pull/712#discussion_r847175597
##########
maven-core/src/main/java/org/apache/maven/artifact/transform/ConsumerPomTransformer.java:
##########
@@ -0,0 +1,140 @@
+package org.apache.maven.artifact.transform;
+
+/*
+ * 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.
+ */
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.TransformerContext;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM install and deploy transformer.
+ */
+@Named( ConsumerPomTransformer.NAME )
+@Singleton
+public class ConsumerPomTransformer implements InstallRequestTransformer, DeployRequestTransformer
Review Comment:
That's fine, Maven (and resolver) is already full of "internal" things, not MEANT to be extended by end users. We can make it clear here as well, but putting this code into some "internal" package instead (to not look like "API-ish thing".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven] cstamas commented on a diff in pull request #712: Provide file transformer API replacement in Maven
Posted by GitBox <gi...@apache.org>.
cstamas commented on code in PR #712:
URL: https://github.com/apache/maven/pull/712#discussion_r847213990
##########
maven-core/src/main/java/org/apache/maven/artifact/transform/ConsumerPomTransformer.java:
##########
@@ -0,0 +1,140 @@
+package org.apache.maven.artifact.transform;
+
+/*
+ * 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.
+ */
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileTime;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.TransformerContext;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM install and deploy transformer.
+ */
+@Named( ConsumerPomTransformer.NAME )
+@Singleton
+public class ConsumerPomTransformer implements InstallRequestTransformer, DeployRequestTransformer
+{
+ public static final String NAME = "consumer-pom";
+
+ private final Provider<MavenSession> mavenSessionProvider;
+
+ @Inject
+ public ConsumerPomTransformer( Provider<MavenSession> mavenSessionProvider )
+ {
+ this.mavenSessionProvider = mavenSessionProvider;
+ }
+
+ @Override
+ public DeployRequest transformDeployRequest( RepositorySystemSession session,
+ DeployRequest deployRequest )
+ {
+ MavenSession mavenSession = mavenSessionProvider.get();
+ if ( !Features.buildConsumer( mavenSession.getUserProperties() ).isActive() )
+ {
+ return deployRequest;
+ }
+ return deployRequest.setArtifacts( transformArtifacts( mavenSession, deployRequest.getArtifacts() ) );
+ }
+
+ @Override
+ public InstallRequest transformInstallRequest( RepositorySystemSession session,
+ InstallRequest installRequest )
+ {
+ MavenSession mavenSession = mavenSessionProvider.get();
+ if ( !Features.buildConsumer( mavenSession.getUserProperties() ).isActive() )
+ {
+ return installRequest;
+ }
+ return installRequest.setArtifacts( transformArtifacts( mavenSession, installRequest.getArtifacts() ) );
+ }
+
+ private Collection<Artifact> transformArtifacts( MavenSession mavenSession, Collection<Artifact> artifacts )
+ {
+ TransformerContext context = (TransformerContext) mavenSession
+ .getRepositorySession().getData().get( TransformerContext.KEY );
+ if ( context == null )
+ {
+ return artifacts;
+ }
+ ArrayList<Artifact> result = new ArrayList<>( artifacts.size() );
+ for ( Artifact artifact : artifacts )
+ {
+ if ( "pom".equals( artifact.getExtension() ) )
+ {
+ Path buildOutputDirectory = Paths.get(
+ mavenSession.getCurrentProject().getBuild().getDirectory() );
+ Path originalPom = artifact.getFile().toPath();
+ Path transformedPom = buildOutputDirectory.resolve( NAME + ".xml" );
+ try
+ {
+ FileTime originalPomTs = Files.getLastModifiedTime( originalPom );
+ FileTime transformedPomTs = Files.isRegularFile( transformedPom )
+ ? Files.getLastModifiedTime( transformedPom ) : null;
+
+ if ( !originalPomTs.equals( transformedPomTs ) )
+ {
+ // save it: either does not exist or TS differ
+ Files.createDirectories( transformedPom.getParent() );
+ try ( InputStream inputStream = new ConsumerModelSourceTransformer()
+ .transform( originalPom, context ) )
+ {
+ Files.copy( inputStream, transformedPom );
Review Comment:
Not to forget upcoming Maven API, that also (may) solve this issue. Ultimate goal is to confine Resolver fully into Maven, and unlike today (just think about sonatype/eclipse package change) not have it littered into plugins, but offer API for all the use cases plugins would do, and make them "come back to core" instead, where all kind of things would become possible, and would be safe as well from future changes like possibly eclipse/apache package change of resolver for example... (not that it's about to happen tomorrow, but once in future will for sure).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org