diff --git a/tools/plugs-maven-plugin/pom.xml b/tools/plugs-maven-plugin/pom.xml
index 10859e9..8dc3d5e 100644
--- a/tools/plugs-maven-plugin/pom.xml
+++ b/tools/plugs-maven-plugin/pom.xml
@@ -169,5 +169,16 @@
true
+
+
+
+ maven-compiler-plugin
+
+
+ -Xlint:all,-processing
+
+
+
+
diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/PackagePlugMojo.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/PackagePlugMojo.java
index 7134b18..451a1a2 100644
--- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/PackagePlugMojo.java
+++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/PackagePlugMojo.java
@@ -16,6 +16,7 @@
package pl.wavesoftware.plugs.tools.maven.plugin;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -84,6 +85,18 @@ final class PackagePlugMojo extends AbstractMojo {
)
private MavenProject project;
+ /**
+ * The Maven session.
+ *
+ * @since 0.1.0
+ */
+ @Parameter(
+ defaultValue = "${session}",
+ required = true,
+ readonly = true
+ )
+ private MavenSession session;
+
/**
* Classifier to add to the repackaged archive. If not given, classifier
* "plug" will be used. If given, the classifier will also be used
@@ -233,6 +246,7 @@ private void attachArtifactIfNeeded(PackagerConfiguration configuration) {
private PackagerConfiguration createConfiguration() {
return factories.configuration().create(
project,
+ session,
logger,
classifier,
attach,
diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/ArtifactMapper.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/ArtifactMapper.java
index dd60134..601c749 100644
--- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/ArtifactMapper.java
+++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/ArtifactMapper.java
@@ -16,7 +16,8 @@
package pl.wavesoftware.plugs.tools.maven.plugin.mapper;
-import org.apache.maven.model.Dependency;
+import io.vavr.collection.Traversable;
+import pl.wavesoftware.plugs.tools.maven.plugin.model.ResolvableDependency;
import pl.wavesoftware.plugs.tools.packager.core.model.Artifact;
/**
@@ -26,5 +27,5 @@
public interface ArtifactMapper {
Artifact generalize(org.apache.maven.artifact.Artifact artifact);
org.apache.maven.artifact.Artifact mavenize(Artifact artifact);
- Artifact map(Dependency dependency);
+ Traversable map(ResolvableDependency dependency);
}
diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/ArtifactMapperImpl.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/ArtifactMapperImpl.java
index a0e46e5..59c7d3d 100644
--- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/ArtifactMapperImpl.java
+++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/ArtifactMapperImpl.java
@@ -16,8 +16,15 @@
package pl.wavesoftware.plugs.tools.maven.plugin.mapper;
-import org.apache.maven.model.Dependency;
+import io.vavr.collection.HashSet;
+import io.vavr.collection.Traversable;
+import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
+import org.apache.maven.artifact.repository.RepositoryRequest;
+import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.repository.RepositorySystem;
+import pl.wavesoftware.plugs.tools.maven.plugin.model.ResolvableDependency;
import pl.wavesoftware.plugs.tools.packager.core.model.Artifact;
import javax.inject.Inject;
@@ -31,10 +38,15 @@
final class ArtifactMapperImpl implements ArtifactMapper {
private final RepositorySystem repositorySystem;
+ private final ArtifactResolver artifactResolver;
@Inject
- ArtifactMapperImpl(RepositorySystem repositorySystem) {
+ ArtifactMapperImpl(
+ RepositorySystem repositorySystem,
+ ArtifactResolver artifactResolver
+ ) {
this.repositorySystem = repositorySystem;
+ this.artifactResolver = artifactResolver;
}
@Override
@@ -47,16 +59,26 @@ public org.apache.maven.artifact.Artifact mavenize(Artifact artifact) {
if (artifact instanceof MavenArtifact) {
return ((MavenArtifact) artifact).getDelegate();
}
- if (artifact instanceof MavenDependency) {
- return ((MavenDependency) artifact).asArtifact();
- }
throw new UnsupportedOperationException(
"Not supported artifact type: " + artifact.getClass()
);
}
@Override
- public Artifact map(Dependency dependency) {
- return new MavenDependency(repositorySystem, dependency);
+ public Traversable map(ResolvableDependency resolvable) {
+ return resolve(resolvable).map(this::generalize);
+ }
+
+ private Traversable resolve(ResolvableDependency resolvable) {
+ RepositoryRequest repositoryRequest = DefaultRepositoryRequest.getRepositoryRequest(
+ resolvable.mavenSession(), resolvable.mavenProject()
+ );
+ ArtifactResolutionRequest request = new ArtifactResolutionRequest(repositoryRequest);
+ request.setResolveTransitively(true);
+ org.apache.maven.artifact.Artifact artifact =
+ repositorySystem.createDependencyArtifact(resolvable.dependency());
+ request.setArtifact(artifact);
+ ArtifactResolutionResult response = artifactResolver.resolve(request);
+ return HashSet.ofAll(response.getArtifacts());
}
}
diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenArtifact.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenArtifact.java
index e710b40..9b82496 100644
--- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenArtifact.java
+++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenArtifact.java
@@ -56,4 +56,11 @@ public Path path() {
public ArtifactType type() {
return ArtifactType.fromPackging(getDelegate().getType());
}
+
+ @Override
+ public String toString() {
+ return "MavenArtifact{" +
+ name() + "@" + version() +
+ '}';
+ }
}
diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenBackedProject.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenBackedProject.java
index 01395ed..6a9cd50 100644
--- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenBackedProject.java
+++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenBackedProject.java
@@ -19,8 +19,10 @@
import io.vavr.Lazy;
import io.vavr.collection.HashSet;
import io.vavr.collection.Set;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
+import pl.wavesoftware.plugs.tools.maven.plugin.model.ResolvableDependency;
import pl.wavesoftware.plugs.tools.packager.core.model.Artifact;
import pl.wavesoftware.plugs.tools.packager.core.model.Project;
@@ -33,6 +35,7 @@
final class MavenBackedProject implements Project {
private final ArtifactMapper artifactMapper;
private final MavenProject mavenProject;
+ private final MavenSession mavenSession;
private final Path path;
private final String finalName;
private final String classifier;
@@ -43,12 +46,14 @@ final class MavenBackedProject implements Project {
MavenBackedProject(
ArtifactMapper artifactMapper,
MavenProject mavenProject,
+ MavenSession mavenSession,
Path path,
String finalName,
String classifier
) {
this.artifactMapper = artifactMapper;
this.mavenProject = mavenProject;
+ this.mavenSession = mavenSession;
this.path = path;
this.finalName = finalName;
this.classifier = classifier;
@@ -57,6 +62,11 @@ final class MavenBackedProject implements Project {
importsLazy = Lazy.of(this::calculateImports);
}
+ @Override
+ public Path buildFilePath() {
+ return mavenProject.getBasedir().toPath().resolve("pom.xml");
+ }
+
@Override
public Artifact mainArtifact() {
return artifactMapper.generalize(mavenProject.getArtifact());
@@ -91,14 +101,20 @@ private Set calculateDependencies() {
return HashSet
.ofAll(mavenProject.getDependencies())
.reject(MavenBackedProject::hasProvidedScope)
- .map(artifactMapper::map);
+ .map(this::asResolvable)
+ .flatMap(artifactMapper::map);
}
private Set calculateImports() {
return HashSet
.ofAll(mavenProject.getDependencies())
.filter(MavenBackedProject::hasProvidedScope)
- .map(artifactMapper::map);
+ .map(this::asResolvable)
+ .flatMap(artifactMapper::map);
+ }
+
+ private ResolvableDependency asResolvable(Dependency dependency) {
+ return new ResolvableDependency(dependency, mavenProject, mavenSession);
}
private static boolean hasProvidedScope(Dependency dependency) {
diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenDependency.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenDependency.java
deleted file mode 100644
index 54c3ead..0000000
--- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenDependency.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2019 Wave Software
- *
- * Licensed 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 pl.wavesoftware.plugs.tools.maven.plugin.mapper;
-
-import com.github.zafarkhaja.semver.Version;
-import io.vavr.Lazy;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.repository.RepositorySystem;
-import pl.wavesoftware.plugs.tools.packager.core.model.Artifact;
-import pl.wavesoftware.plugs.tools.packager.core.model.ArtifactType;
-
-import java.nio.file.Path;
-
-final class MavenDependency implements Artifact {
- private final RepositorySystem repositorySystem;
- private final Dependency delegate;
- private final Lazy artifactLazy = Lazy.of(
- this::mapAsArtifact
- );
-
- MavenDependency(RepositorySystem repositorySystem, Dependency dependency) {
- this.repositorySystem = repositorySystem;
- this.delegate = dependency;
- }
-
- @Override
- public String name() {
- return delegate.getArtifactId();
- }
-
- @Override
- public Version version() {
- return Version.valueOf(delegate.getVersion());
- }
-
- @Override
- public Path path() {
- org.apache.maven.artifact.Artifact artifact = asArtifact();
- return artifact.getFile().toPath();
- }
-
- @Override
- public ArtifactType type() {
- return ArtifactType.fromPackging(delegate.getType());
- }
-
- org.apache.maven.artifact.Artifact asArtifact() {
- return artifactLazy.get();
- }
-
- private org.apache.maven.artifact.Artifact mapAsArtifact() {
- return repositorySystem.createDependencyArtifact(delegate);
- }
-}
diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenPackagerConfiguration.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenPackagerConfiguration.java
index 8ebc379..50f131a 100644
--- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenPackagerConfiguration.java
+++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenPackagerConfiguration.java
@@ -17,6 +17,7 @@
package pl.wavesoftware.plugs.tools.maven.plugin.mapper;
import io.vavr.Lazy;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import pl.wavesoftware.plugs.tools.packager.core.model.PackagerConfiguration;
@@ -35,6 +36,7 @@ final class MavenPackagerConfiguration implements PackagerConfiguration {
private final ArtifactMapper artifactMapper;
private final Logger logger;
private final MavenProject mavenProject;
+ private final MavenSession mavenSession;
private final Supplier project;
private final String classifier;
private final boolean attach;
@@ -46,6 +48,7 @@ final class MavenPackagerConfiguration implements PackagerConfiguration {
ArtifactMapper artifactMapper,
Logger logger,
MavenProject project,
+ MavenSession session,
String classifier,
boolean attach,
File outputDirectory,
@@ -54,6 +57,7 @@ final class MavenPackagerConfiguration implements PackagerConfiguration {
this.artifactMapper = artifactMapper;
this.logger = logger;
this.mavenProject = project;
+ this.mavenSession = session;
this.classifier = classifier;
this.attach = attach;
this.outputDirectory = outputDirectory;
@@ -86,6 +90,7 @@ private Project calculateProject() {
return new MavenBackedProject(
artifactMapper,
mavenProject,
+ mavenSession,
outputDirectory.toPath(),
finalName,
classifier
diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenPackagerConfigurationFactory.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenPackagerConfigurationFactory.java
index 8de55e6..a276375 100644
--- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenPackagerConfigurationFactory.java
+++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenPackagerConfigurationFactory.java
@@ -16,6 +16,7 @@
package pl.wavesoftware.plugs.tools.maven.plugin.mapper;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import pl.wavesoftware.plugs.tools.packager.core.model.PackagerConfiguration;
@@ -41,6 +42,7 @@ final class MavenPackagerConfigurationFactory implements PackagerConfigurationFa
@Override
public PackagerConfiguration create(
MavenProject project,
+ MavenSession session,
Logger logger,
String classifier,
boolean attach,
@@ -51,6 +53,7 @@ public PackagerConfiguration create(
artifactMapper,
logger,
project,
+ session,
classifier,
attach,
outputDirectory,
diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/PackagerConfigurationFactory.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/PackagerConfigurationFactory.java
index 0d53e16..75aaab3 100644
--- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/PackagerConfigurationFactory.java
+++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/PackagerConfigurationFactory.java
@@ -16,6 +16,7 @@
package pl.wavesoftware.plugs.tools.maven.plugin.mapper;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import pl.wavesoftware.plugs.tools.packager.core.model.PackagerConfiguration;
@@ -33,6 +34,7 @@ public interface PackagerConfigurationFactory {
* Creates a configuration
*
* @param project a maven project
+ * @param session a maven session
* @param logger a logger
* @param classifier classifier of plug to create
* @param attach should created plug be attached to reactor
@@ -42,6 +44,7 @@ public interface PackagerConfigurationFactory {
*/
PackagerConfiguration create(
MavenProject project,
+ MavenSession session,
Logger logger,
String classifier,
boolean attach,
diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/model/ResolvableDependency.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/model/ResolvableDependency.java
new file mode 100644
index 0000000..0f98c5b
--- /dev/null
+++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/model/ResolvableDependency.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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 pl.wavesoftware.plugs.tools.maven.plugin.model;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.project.MavenProject;
+
+public final class ResolvableDependency {
+ private final Dependency dependency;
+ private final MavenProject mavenProject;
+ private final MavenSession mavenSession;
+
+ public ResolvableDependency(
+ Dependency dependency,
+ MavenProject mavenProject,
+ MavenSession mavenSession
+ ) {
+ this.dependency = dependency;
+ this.mavenProject = mavenProject;
+ this.mavenSession = mavenSession;
+ }
+
+ public Dependency dependency() {
+ return dependency;
+ }
+
+ public MavenProject mavenProject() {
+ return mavenProject;
+ }
+
+ public MavenSession mavenSession() {
+ return mavenSession;
+ }
+}
diff --git a/tools/plugs-maven-plugin/src/test/java/pl/wavesoftware/maven/testing/junit5/DefaultMojoConfigurator.java b/tools/plugs-maven-plugin/src/test/java/pl/wavesoftware/maven/testing/junit5/DefaultMojoConfigurator.java
index 00d0cfb..6dc4036 100644
--- a/tools/plugs-maven-plugin/src/test/java/pl/wavesoftware/maven/testing/junit5/DefaultMojoConfigurator.java
+++ b/tools/plugs-maven-plugin/src/test/java/pl/wavesoftware/maven/testing/junit5/DefaultMojoConfigurator.java
@@ -16,15 +16,35 @@
package pl.wavesoftware.maven.testing.junit5;
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.DefaultMavenExecutionResult;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionRequestPopulationException;
+import org.apache.maven.execution.MavenExecutionRequestPopulator;
+import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilder;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.apache.maven.settings.MavenSettingsBuilder;
+import org.apache.maven.settings.Settings;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import java.io.File;
+import java.io.IOException;
import java.nio.file.Path;
+import java.util.Collections;
import java.util.Optional;
import java.util.function.Supplier;
+import static pl.wavesoftware.eid.utils.EidPreconditions.checkNotNull;
+
/**
* @author Krzysztof Suszynski
* @since 0.1.0
@@ -39,13 +59,18 @@ final class DefaultMojoConfigurator implements MojoConfigurator {
@Override
public MavenSession getMavenSession(MojoRule rule, Path pomDirectory) throws Exception {
+ // create execution request
+ MavenExecutionRequest request = createMavenExecutionRequest(rule);
+
// setup with pom
- MavenProject project = rule.readMavenProject(pomDirectory.toFile());
+ MavenProject project = readMavenProject(
+ rule, request, pomDirectory.toFile()
+ );
customizer.get().ifPresent(customizer -> customizer.customize(project));
// Generate session
- return rule.newMavenSession(project);
+ return newMavenSession(rule, request, project);
}
@Override
@@ -53,4 +78,49 @@ public MojoExecution getMojoExecution(MojoRule rule, String goal) {
// Generate PackagerConfiguration and Mojo for testing
return rule.newMojoExecution(goal);
}
+
+ private MavenExecutionRequest createMavenExecutionRequest(MojoRule rule)
+ throws ComponentLookupException, IOException,
+ XmlPullParserException, MavenExecutionRequestPopulationException {
+
+ PlexusContainer container = rule.getContainer();
+ MavenExecutionRequest request = new DefaultMavenExecutionRequest();
+ MavenExecutionRequestPopulator requestPopulator =
+ container.lookup(MavenExecutionRequestPopulator.class);
+ MavenSettingsBuilder settingsBuilder = container.lookup(MavenSettingsBuilder.class);
+ Settings settings = settingsBuilder.buildSettings();
+ requestPopulator.populateFromSettings(request, settings);
+ requestPopulator.populateDefaults(request);
+ return request;
+ }
+
+ private MavenProject readMavenProject(
+ MojoRule rule, MavenExecutionRequest request, File basedir
+ ) throws Exception {
+ File pom = new File(basedir, "pom.xml");
+ request.setBaseDirectory(basedir);
+ ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
+ configuration.setRepositorySession(new DefaultRepositorySystemSession());
+ MavenProject project = rule.lookup(ProjectBuilder.class)
+ .build(pom, configuration)
+ .getProject();
+ checkNotNull(project, "20190331:130819");
+ return project;
+ }
+
+ private MavenSession newMavenSession(
+ MojoRule rule, MavenExecutionRequest request, MavenProject project
+ ) {
+ MavenExecutionResult result = new DefaultMavenExecutionResult();
+
+ MavenSession session = new MavenSession(
+ rule.getContainer(),
+ MavenRepositorySystemUtils.newSession(),
+ request,
+ result
+ );
+ session.setCurrentProject(project);
+ session.setProjects(Collections.singletonList(project));
+ return session;
+ }
}
diff --git a/tools/plugs-maven-plugin/src/test/java/pl/wavesoftware/maven/testing/junit5/MojoBuilderImpl.java b/tools/plugs-maven-plugin/src/test/java/pl/wavesoftware/maven/testing/junit5/MojoBuilderImpl.java
index cb157fb..681a902 100644
--- a/tools/plugs-maven-plugin/src/test/java/pl/wavesoftware/maven/testing/junit5/MojoBuilderImpl.java
+++ b/tools/plugs-maven-plugin/src/test/java/pl/wavesoftware/maven/testing/junit5/MojoBuilderImpl.java
@@ -18,6 +18,7 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.testing.MojoRule;
@@ -72,6 +73,8 @@ mojoRule, getPomDirectory()
mojoRule,
goal
);
+ LegacySupport legacySupport = mojoRule.lookup(LegacySupport.class);
+ legacySupport.setSession(session);
org.apache.maven.plugin.Mojo mojo =
mojoRule.lookupConfiguredMojo(session, execution);
return type.cast(mojo);
diff --git a/tools/plugs-maven-plugin/src/test/resources/code-with-deps/pom.xml b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/pom.xml
index 91a85a8..70dab07 100644
--- a/tools/plugs-maven-plugin/src/test/resources/code-with-deps/pom.xml
+++ b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/pom.xml
@@ -16,16 +16,27 @@
4.0.0
+
+ org.springframework.boot
+ spring-boot-parent
+ 2.1.3.RELEASE
+
+
org.example
code-with-deps
0.1.0
+
+ UTF-8
+ UTF-8
+ 1.8
+ ${maven.compiler.source}
+
+
- org.springframework
- spring-context
- 5.1.5.RELEASE
- provided
+ org.springframework.boot
+ spring-boot-autoconfigure
@@ -33,5 +44,44 @@
apiguardian-api
1.0.0
+
+
+ com.google.code.findbugs
+ jsr305
+ 3.0.2
+
+
+
+ org.osgi
+ osgi.core
+ 7.0.0
+ provided
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+ org.junit.platform
+ junit-platform-launcher
+ test
+
+
+ org.mockito
+ mockito-junit-jupiter
+ test
+
+
+ org.assertj
+ assertj-core
+ test
+
diff --git a/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/Activator.java b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/Activator.java
new file mode 100644
index 0000000..74f2e81
--- /dev/null
+++ b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/Activator.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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 pl.wavesoftware.example.code;
+
+import org.apiguardian.api.API;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+
+import javax.annotation.Nullable;
+import java.util.Optional;
+
+import static org.apiguardian.api.API.Status.STABLE;
+
+@API(status = STABLE)
+final class Activator implements BundleActivator {
+
+ @Nullable
+ private ConfigurableApplicationContext applicationContext;
+ @Nullable
+ private ServiceRegistration registration;
+
+ public void start(BundleContext context) {
+ applicationContext = new AnnotationConfigApplicationContext(Context.class);
+ registration = context.registerService(
+ HelloService.class,
+ applicationContext.getBean(HelloService.class),
+ null
+ );
+ }
+
+ public void stop(BundleContext context) {
+ Optional.ofNullable(registration)
+ .ifPresent(ServiceRegistration::unregister);
+ Optional.ofNullable(applicationContext)
+ .ifPresent(ConfigurableApplicationContext::close);
+ }
+}
diff --git a/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/Context.java b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/Context.java
new file mode 100644
index 0000000..73e6396
--- /dev/null
+++ b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/Context.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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 pl.wavesoftware.example.code;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 0.1.0
+ */
+@SpringBootApplication
+class Context {
+ public static void main(String[] args) {
+ SpringApplication.run(Context.class, args);
+ }
+}
diff --git a/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/HelloService.java b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/HelloService.java
index babf1b5..f4326d0 100644
--- a/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/HelloService.java
+++ b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/HelloService.java
@@ -1,14 +1,26 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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 pl.wavesoftware.example.code;
import org.apiguardian.api.API;
-import org.springframework.stereotype.Service;
import static org.apiguardian.api.API.Status.STABLE;
-@Service
@API(status = STABLE)
-public class HelloService {
- String hello() {
- return "Hello from Plug";
- }
+public interface HelloService {
+ String hello();
}
diff --git a/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/HelloServiceImpl.java b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/HelloServiceImpl.java
new file mode 100644
index 0000000..7201c2b
--- /dev/null
+++ b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/HelloServiceImpl.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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 pl.wavesoftware.example.code;
+
+import org.springframework.stereotype.Service;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 0.1.0
+ */
+@Service
+final class HelloServiceImpl implements HelloService {
+ public String hello() {
+ return "Hello from Plug!";
+ }
+}
diff --git a/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/package-info.java b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/package-info.java
new file mode 100644
index 0000000..6fcbcf5
--- /dev/null
+++ b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/main/java/pl/wavesoftware/example/code/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 0.1.0
+ */
+@ParametersAreNonnullByDefault
+package pl.wavesoftware.example.code;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/test/java/pl/wavesoftware/example/code/ActivatorTest.java b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/test/java/pl/wavesoftware/example/code/ActivatorTest.java
new file mode 100644
index 0000000..7a02233
--- /dev/null
+++ b/tools/plugs-maven-plugin/src/test/resources/code-with-deps/src/test/java/pl/wavesoftware/example/code/ActivatorTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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 pl.wavesoftware.example.code;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 0.1.0
+ */
+@ExtendWith(MockitoExtension.class)
+class ActivatorTest {
+
+ private Activator activator = new Activator();
+
+ @Mock
+ private BundleContext bundleContext;
+
+ @Mock
+ private ServiceRegistration serviceRegistration;
+
+ @Captor
+ private ArgumentCaptor helloServiceArgumentCaptor;
+
+ @Test
+ void startAndStop() {
+ // then
+ verify(bundleContext).registerService(
+ eq(HelloService.class),
+ helloServiceArgumentCaptor.capture(),
+ isNull()
+ );
+ HelloService service = helloServiceArgumentCaptor.getValue();
+ assertThat(service.hello()).isEqualTo("Hello from Plug!");
+ }
+
+ @BeforeEach
+ void before() {
+ when(bundleContext.registerService(
+ eq(HelloService.class), any(HelloService.class), any()
+ )).thenReturn(serviceRegistration);
+ activator.start(bundleContext);
+ }
+
+ @AfterEach
+ void after() {
+ activator.stop(bundleContext);
+ verify(serviceRegistration).unregister();
+
+ Mockito.validateMockitoUsage();
+ Mockito.verifyNoMoreInteractions(bundleContext, serviceRegistration);
+ }
+
+}
diff --git a/tools/plugs-packager-core/pom.xml b/tools/plugs-packager-core/pom.xml
index 597f686..188dd09 100644
--- a/tools/plugs-packager-core/pom.xml
+++ b/tools/plugs-packager-core/pom.xml
@@ -65,6 +65,14 @@
org.apache.commons
commons-compress
+
+
+
+ pl.wavesoftware.plugs
+ testing
+ ${project.version}
+ test
+
diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultPackager.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultPackager.java
index 1d580ac..e7e129a 100644
--- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultPackager.java
+++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultPackager.java
@@ -188,7 +188,7 @@ private void repackage(
}
}
- private JarWriter newJarWriter(Path destination) throws RepackageFailed {
+ private static JarWriter newJarWriter(Path destination) throws RepackageFailed {
return tring(() -> new JarWriter(destination)).or(
"Can't create a jar at destination: {}",
destination
diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultPackagerFactory.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultPackagerFactory.java
index ced55b5..488be1d 100644
--- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultPackagerFactory.java
+++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultPackagerFactory.java
@@ -53,7 +53,7 @@ public Packager create(
Filter filter
) {
RepackagingIsRequired condition = conditionFactory.create(
- configuration.coordinates()
+ configuration.coordinates(), configuration.project()
);
return new DefaultPackager(
configuration,
diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultRepackagingIsRequired.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultRepackagingIsRequired.java
index 366a836..cd7f33a 100644
--- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultRepackagingIsRequired.java
+++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultRepackagingIsRequired.java
@@ -16,8 +16,9 @@
package pl.wavesoftware.plugs.tools.packager.core;
-import pl.wavesoftware.plugs.tools.packager.core.jar.FileDigest;
+import pl.wavesoftware.plugs.tools.packager.core.digest.ProjectDigest;
import pl.wavesoftware.plugs.tools.packager.core.model.PackagerCoordinates;
+import pl.wavesoftware.plugs.tools.packager.core.model.Project;
import pl.wavesoftware.plugs.tools.packager.core.model.RepackagingIsRequired;
import java.io.File;
@@ -33,18 +34,20 @@
* @author Krzysztof Suszynski
* @since 0.1.0
*/
-final class DefaultRepackagingIsRequired
- implements RepackagingIsRequired {
+final class DefaultRepackagingIsRequired implements RepackagingIsRequired {
private final PackagerCoordinates coordinates;
- private final FileDigest fileDigest;
+ private final Project project;
+ private final ProjectDigest projectDigest;
DefaultRepackagingIsRequired(
PackagerCoordinates coordinates,
- FileDigest fileDigest
+ Project project,
+ ProjectDigest projectDigest
) {
this.coordinates = coordinates;
- this.fileDigest = fileDigest;
+ this.project = project;
+ this.projectDigest = projectDigest;
}
@Override
@@ -60,7 +63,7 @@ private boolean alreadyRepackaged() throws IOException {
}
try (JarFile jarFile = new JarFile(targetFile)) {
Manifest manifest = jarFile.getManifest();
- CharSequence digest = fileDigest.digest(sourcePath);
+ CharSequence digest = projectDigest.digest(project);
return manifest != null
&& digest.equals(manifest.getMainAttributes().getValue(PLUGS_DIGEST_ATTRIBUTE));
}
diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultRepackagingIsRequiredFactory.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultRepackagingIsRequiredFactory.java
index cea2407..f68c319 100644
--- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultRepackagingIsRequiredFactory.java
+++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/DefaultRepackagingIsRequiredFactory.java
@@ -16,8 +16,9 @@
package pl.wavesoftware.plugs.tools.packager.core;
-import pl.wavesoftware.plugs.tools.packager.core.jar.FileDigest;
+import pl.wavesoftware.plugs.tools.packager.core.digest.ProjectDigest;
import pl.wavesoftware.plugs.tools.packager.core.model.PackagerCoordinates;
+import pl.wavesoftware.plugs.tools.packager.core.model.Project;
import pl.wavesoftware.plugs.tools.packager.core.model.RepackagingIsRequired;
import javax.inject.Inject;
@@ -31,16 +32,18 @@
final class DefaultRepackagingIsRequiredFactory
implements RepackagingIsRequiredFactory {
- private final FileDigest digest;
+ private final ProjectDigest digest;
@Inject
- DefaultRepackagingIsRequiredFactory(FileDigest digest) {
+ DefaultRepackagingIsRequiredFactory(ProjectDigest digest) {
this.digest = digest;
}
@Override
- public RepackagingIsRequired create(PackagerCoordinates coordinates) {
- return new DefaultRepackagingIsRequired(coordinates, digest);
+ public RepackagingIsRequired create(
+ PackagerCoordinates coordinates, Project project
+ ) {
+ return new DefaultRepackagingIsRequired(coordinates, project, digest);
}
}
diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/RepackagingIsRequiredFactory.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/RepackagingIsRequiredFactory.java
index 4c4b5f7..7d86a6e 100644
--- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/RepackagingIsRequiredFactory.java
+++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/RepackagingIsRequiredFactory.java
@@ -17,6 +17,7 @@
package pl.wavesoftware.plugs.tools.packager.core;
import pl.wavesoftware.plugs.tools.packager.core.model.PackagerCoordinates;
+import pl.wavesoftware.plugs.tools.packager.core.model.Project;
import pl.wavesoftware.plugs.tools.packager.core.model.RepackagingIsRequired;
/**
@@ -30,7 +31,8 @@ public interface RepackagingIsRequiredFactory {
* Create a condition that is true if packaging is required.
*
* @param coordinates a coordinates of operation
+ * @param project a project
* @return a condition
*/
- RepackagingIsRequired create(PackagerCoordinates coordinates);
+ RepackagingIsRequired create(PackagerCoordinates coordinates, Project project);
}
diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/FileDigest.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/digest/ProjectDigest.java
similarity index 75%
rename from tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/FileDigest.java
rename to tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/digest/ProjectDigest.java
index e1b4331..d3bc65f 100644
--- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/FileDigest.java
+++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/digest/ProjectDigest.java
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-package pl.wavesoftware.plugs.tools.packager.core.jar;
+package pl.wavesoftware.plugs.tools.packager.core.digest;
+
+import pl.wavesoftware.plugs.tools.packager.core.model.Project;
import java.io.IOException;
-import java.nio.file.Path;
/**
* A calculator of a digest of a file
@@ -25,13 +26,13 @@
* @author Krzysztof Suszynski
* @since 0.1.0
*/
-public interface FileDigest {
+public interface ProjectDigest {
/**
- * Digest a path to a file
+ * Digest a project
*
- * @param path a path to digest
+ * @param project a project to digest
* @return a digest
* @throws IOException if cant be read
*/
- CharSequence digest(Path path) throws IOException;
+ CharSequence digest(Project project) throws IOException;
}
diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/FileDigestImpl.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/digest/ProjectDigestImpl.java
similarity index 59%
rename from tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/FileDigestImpl.java
rename to tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/digest/ProjectDigestImpl.java
index adab60e..aa0de7b 100644
--- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/FileDigestImpl.java
+++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/digest/ProjectDigestImpl.java
@@ -14,7 +14,9 @@
* limitations under the License.
*/
-package pl.wavesoftware.plugs.tools.packager.core.jar;
+package pl.wavesoftware.plugs.tools.packager.core.digest;
+
+import pl.wavesoftware.plugs.tools.packager.core.model.Project;
import javax.inject.Named;
import java.io.IOException;
@@ -30,13 +32,17 @@
* @since 0.1.0
*/
@Named
-final class FileDigestImpl implements FileDigest {
+final class ProjectDigestImpl implements ProjectDigest {
@Override
- public CharSequence digest(Path path) throws IOException {
- checkArgument(path.toFile().isFile(), "20190131:221929");
+ public CharSequence digest(Project project) throws IOException {
+ Path sourcePath = project.mainArtifact().path();
+ Path buildFilePath = project.buildFilePath();
+ checkArgument(sourcePath.toFile().isFile(), "20190131:221929");
CRC32 digest = new CRC32();
- digest.update(path.toAbsolutePath().toString().getBytes(UTF_8));
- digest.update(Long.toHexString(Files.size(path)).getBytes(UTF_8));
+ digest.update(sourcePath.toAbsolutePath().toString().getBytes(UTF_8));
+ digest.update(Long.toHexString(Files.size(sourcePath)).getBytes(UTF_8));
+ digest.update(Long.toHexString(Files.size(buildFilePath)).getBytes(UTF_8));
+ digest.update(Long.toHexString(buildFilePath.toFile().lastModified()).getBytes(UTF_8));
return Long.toHexString(Math.abs(digest.getValue()));
}
}
diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/manifest/ManifestBuilderImpl.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/manifest/ManifestBuilderImpl.java
index e96b762..3947eaf 100644
--- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/manifest/ManifestBuilderImpl.java
+++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/manifest/ManifestBuilderImpl.java
@@ -19,7 +19,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.wavesoftware.plugs.api.PlugsVersion;
-import pl.wavesoftware.plugs.tools.packager.core.jar.FileDigest;
+import pl.wavesoftware.plugs.tools.packager.core.digest.ProjectDigest;
import pl.wavesoftware.plugs.tools.packager.core.model.Project;
import pl.wavesoftware.plugs.tools.packager.core.model.RepackageFailed;
@@ -44,10 +44,10 @@ final class ManifestBuilderImpl implements ManifestBuilder {
private static final Logger LOGGER =
LoggerFactory.getLogger(ManifestBuilderImpl.class);
- private final FileDigest digest;
+ private final ProjectDigest digest;
@Inject
- ManifestBuilderImpl(FileDigest digest) {
+ ManifestBuilderImpl(ProjectDigest digest) {
this.digest = digest;
}
@@ -69,7 +69,7 @@ public Manifest buildManifest(
manifest = new Manifest(manifest);
Attributes attributes = manifest.getMainAttributes();
String plugsVersion = PlugsVersion.getVersion();
- CharSequence hash = tring(() -> digest.digest(sourcePath)).or(
+ CharSequence hash = tring(() -> digest.digest(project)).or(
"Can't calculate digest from source jar: {}",
sourcePath
);
diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/Project.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/Project.java
index 2b3804b..3b77ab6 100644
--- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/Project.java
+++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/Project.java
@@ -28,6 +28,13 @@
*/
public interface Project {
+ /**
+ * A build file path. For ex.: pom.xml
+ *
+ * @return a build file path
+ */
+ Path buildFilePath();
+
/**
* A main artifact of a project
*
diff --git a/tools/plugs-packager-core/src/main/resources/META-INF/sisu/javax.inject.Named b/tools/plugs-packager-core/src/main/resources/META-INF/sisu/javax.inject.Named
index 18def04..4fed7bf 100644
--- a/tools/plugs-packager-core/src/main/resources/META-INF/sisu/javax.inject.Named
+++ b/tools/plugs-packager-core/src/main/resources/META-INF/sisu/javax.inject.Named
@@ -1,4 +1,4 @@
-pl.wavesoftware.plugs.tools.packager.core.jar.FileDigestImpl
+pl.wavesoftware.plugs.tools.packager.core.jar.ProjectDigestImpl
pl.wavesoftware.plugs.tools.packager.core.manifest.ManifestBuilderImpl
pl.wavesoftware.plugs.tools.packager.core.DefaultPackagerFactory
pl.wavesoftware.plugs.tools.packager.core.DefaultRepackagingIsRequiredFactory
diff --git a/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/digest/ProjectDigestImplTest.java b/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/digest/ProjectDigestImplTest.java
new file mode 100644
index 0000000..170c3aa
--- /dev/null
+++ b/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/digest/ProjectDigestImplTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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 pl.wavesoftware.plugs.tools.packager.core.digest;
+
+import com.github.zafarkhaja.semver.Version;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import pl.wavesoftware.plugs.tools.packager.core.model.Artifact;
+import pl.wavesoftware.plugs.tools.packager.core.model.ArtifactType;
+import pl.wavesoftware.plugs.tools.packager.core.model.Project;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 0.1.0
+ */
+@ExtendWith(MockitoExtension.class)
+class ProjectDigestImplTest {
+
+ @Mock
+ Project project;
+
+ @Test
+ void digest() throws IOException, URISyntaxException {
+ // given
+ ProjectDigest digester = new ProjectDigestImpl();
+ Path buildFilePath = Paths.get(getClass().getResource("pom.xml").toURI());
+ Artifact artifact = new Artifact() {
+ @Override
+ public String name() {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public Version version() {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public Path path() {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public ArtifactType type() {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+ };
+ when(project.buildFilePath()).thenReturn(buildFilePath);
+ when(project.mainArtifact()).thenReturn(artifact);
+
+ // when
+ CharSequence digest = digester.digest(project);
+
+ // then
+ assertThat(digest).isEqualTo("22ssdd33");
+ }
+}
diff --git a/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/sample/ProjectSamples.java b/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/sample/ProjectSamples.java
new file mode 100644
index 0000000..4905d6f
--- /dev/null
+++ b/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/sample/ProjectSamples.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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 pl.wavesoftware.plugs.tools.packager.core.sample;
+
+import pl.wavesoftware.plugs.tools.packager.core.model.Project;
+
+import java.util.function.Supplier;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 0.1.0
+ */
+public enum ProjectSamples implements Sample {
+
+ SIMPLE_PROJECT(new SimpleProjectSample());
+
+ private final Supplier project;
+
+ ProjectSamples(Supplier project) {
+ this.project = project;
+ }
+
+ @Override
+ public Project get() {
+ return project.get();
+ }
+}
diff --git a/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/sample/Sample.java b/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/sample/Sample.java
new file mode 100644
index 0000000..189badb
--- /dev/null
+++ b/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/sample/Sample.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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 pl.wavesoftware.plugs.tools.packager.core.sample;
+
+import java.util.function.Supplier;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 0.1.0
+ */
+public interface Sample extends Supplier {
+ default T getSample() {
+ return get();
+ }
+}
diff --git a/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/sample/SimpleProjectSample.java b/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/sample/SimpleProjectSample.java
new file mode 100644
index 0000000..3cace72
--- /dev/null
+++ b/tools/plugs-packager-core/src/test/java/pl/wavesoftware/plugs/tools/packager/core/sample/SimpleProjectSample.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2019 Wave Software
+ *
+ * Licensed 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 pl.wavesoftware.plugs.tools.packager.core.sample;
+
+import pl.wavesoftware.plugs.tools.packager.core.model.Project;
+
+/**
+ * @author Krzysztof Suszynski
+ * @since 0.1.0
+ */
+final class SimpleProjectSample implements Sample {
+ @Override
+ public Project get() {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+}
diff --git a/tools/plugs-packager-core/src/test/resources/pl/wavesoftware/plugs/tools/packager/core/sample/pom.xml b/tools/plugs-packager-core/src/test/resources/pl/wavesoftware/plugs/tools/packager/core/sample/pom.xml
new file mode 100644
index 0000000..9246447
--- /dev/null
+++ b/tools/plugs-packager-core/src/test/resources/pl/wavesoftware/plugs/tools/packager/core/sample/pom.xml
@@ -0,0 +1,22 @@
+
+
+
+ 4.0.0
+ org.example
+ digest-test
+ 0.1.0
+