diff --git a/README.adoc b/README.adoc index 289dc94..bb4481c 100644 --- a/README.adoc +++ b/README.adoc @@ -114,6 +114,17 @@ The `out` configuration changes the module output directory: ---- +When the dependency has a _sources-jar_, it is imported as well as a sources jar, this can be prevented if necessary: + +---- + + ... + false + ... + +---- + + === Compile Ceylon modules The `compile` goal compiles Ceylon modules: diff --git a/pom.xml b/pom.xml index b80eb27..8dcb93c 100644 --- a/pom.xml +++ b/pom.xml @@ -65,11 +65,13 @@ file-management 1.2 + org.apache.maven maven-core @@ -133,7 +135,7 @@ true verify true - compile-default + import-dependency-missing-sources diff --git a/src/it/projects/import-dependency-default/verify.groovy b/src/it/projects/import-dependency-default/verify.groovy index 2dde8d7..b593d78 100644 --- a/src/it/projects/import-dependency-default/verify.groovy +++ b/src/it/projects/import-dependency-default/verify.groovy @@ -1,3 +1,5 @@ def root = new File(basedir, 'target/modules/javax/inject/javax/inject/1') return new File(root, 'javax.inject.javax.inject-1.jar').exists() && - new File(root, 'javax.inject.javax.inject-1.jar.sha1').exists() + new File(root, 'javax.inject.javax.inject-1.jar.sha1').exists() && + new File(root, 'javax.inject.javax.inject-1-sources.jar').exists() && + new File(root, 'javax.inject.javax.inject-1-sources.jar.sha1').exists() diff --git a/src/it/projects/import-dependency-missing-sources/pom.xml b/src/it/projects/import-dependency-missing-sources/pom.xml new file mode 100644 index 0000000..d752c8d --- /dev/null +++ b/src/it/projects/import-dependency-missing-sources/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + org.ceylon-lang.test + compile-default + 1.2.1-SNAPSHOT + + compile-default + + + + + org.ceylon-lang + ceylon-maven-plugin + 1.2.1-SNAPSHOT + + + + import-dependency + + + + + + + javax.portlet + portlet-api + 1.0 + + + + + + + + + + + diff --git a/src/it/projects/import-dependency-missing-sources/verify.groovy b/src/it/projects/import-dependency-missing-sources/verify.groovy new file mode 100644 index 0000000..70e5036 --- /dev/null +++ b/src/it/projects/import-dependency-missing-sources/verify.groovy @@ -0,0 +1,5 @@ +def root = new File(basedir, 'target/modules/javax/portlet/portlet-api/1.0') +return new File(root, 'javax.portlet.portlet-api-1.0.jar').exists() && + new File(root, 'javax.portlet.portlet-api-1.0.jar.sha1').exists() && + !new File(root, 'javax.portlet.portlet-api-1.0-sources.jar').exists() && + !new File(root, 'javax.portlet.portlet-api-1.0-sources.jar.sha1').exists() diff --git a/src/it/projects/import-dependency-no-sources/pom.xml b/src/it/projects/import-dependency-no-sources/pom.xml new file mode 100644 index 0000000..eb92aff --- /dev/null +++ b/src/it/projects/import-dependency-no-sources/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + org.ceylon-lang.test + compile-default + 1.2.1-SNAPSHOT + + compile-default + + + + + org.ceylon-lang + ceylon-maven-plugin + 1.2.1-SNAPSHOT + + + + import-dependency + + + + + + javax.inject + javax.inject + 1 + + false + + + + + + + + + + diff --git a/src/it/projects/import-dependency-no-sources/verify.groovy b/src/it/projects/import-dependency-no-sources/verify.groovy new file mode 100644 index 0000000..cbf0416 --- /dev/null +++ b/src/it/projects/import-dependency-no-sources/verify.groovy @@ -0,0 +1,5 @@ +def root = new File(basedir, 'target/modules/javax/inject/javax/inject/1') +return new File(root, 'javax.inject.javax.inject-1.jar').exists() && + new File(root, 'javax.inject.javax.inject-1.jar.sha1').exists() && + !new File(root, 'javax.inject.javax.inject-1-sources.jar').exists() && + !new File(root, 'javax.inject.javax.inject-1-sources.jar.sha1').exists() diff --git a/src/it/projects/run-no-module/verify.groovy b/src/it/projects/run-no-module/verify.groovy index 877e5e0..a01e7e9 100644 --- a/src/it/projects/run-no-module/verify.groovy +++ b/src/it/projects/run-no-module/verify.groovy @@ -1,2 +1,2 @@ def log = new File(basedir, 'build.log').text -return log.contains('Missing module: mymodule/1.0.0') +return log.contains('Could not find module: mymodule/1.0.0') diff --git a/src/main/java/com/redhat/ceylon/maven/CeylonImportDependencyMojo.java b/src/main/java/com/redhat/ceylon/maven/CeylonImportDependencyMojo.java index 0033e08..105d5d9 100644 --- a/src/main/java/com/redhat/ceylon/maven/CeylonImportDependencyMojo.java +++ b/src/main/java/com/redhat/ceylon/maven/CeylonImportDependencyMojo.java @@ -23,8 +23,10 @@ import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.internal.impl.DefaultRepositorySystem; import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.resolution.ArtifactRequest; +import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; import java.io.File; @@ -51,6 +53,9 @@ public class CeylonImportDependencyMojo extends AbstractMojo { @Parameter(defaultValue = "${repositorySystemSession}", readonly = true, required = true) protected RepositorySystemSession repoSession; + @Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true) + public List remoteRepos; + @Parameter(defaultValue = "${project}", readonly = true) public MavenProject project; @@ -60,6 +65,14 @@ public class CeylonImportDependencyMojo extends AbstractMojo { @Component protected ProjectDependenciesResolver resolver; + private ArtifactResult fetch(Dependency dependency) throws Exception { + Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), dependency.getType(), dependency.getVersion()); + ArtifactRequest request = new ArtifactRequest(); + request.setArtifact(artifact); + request.setRepositories(remoteRepos); + return repoSystem.resolveArtifact(repoSession, request); + } + public void execute() throws MojoExecutionException, MojoFailureException { // Resolve project dependencies @@ -80,32 +93,19 @@ public void execute() throws MojoExecutionException, MojoFailureException { // Prepare all imports for (ModuleImport moduleImport : moduleImports) { Dependency dependency = moduleImport.getDependency(); - ArtifactResult result; - String dependencyVersion = dependency.getVersion(); // Not provided => resolve from project dependencies - if (dependencyVersion == null) { + if (dependency.getVersion() == null) { for (org.eclipse.aether.graph.Dependency managed : dependencies) { if (safeEquals(managed.getArtifact().getGroupId(), dependency.getGroupId()) && safeEquals(managed.getArtifact().getArtifactId(), dependency.getArtifactId()) && safeEquals(managed.getArtifact().getClassifier(), dependency.getClassifier()) && safeEquals(managed.getArtifact().getExtension(), dependency.getType())) { - dependencyVersion = managed.getArtifact().getBaseVersion(); + dependency.setVersion(managed.getArtifact().getBaseVersion()); } } } - try { - Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), dependency.getType(), dependencyVersion); - ArtifactRequest request = new ArtifactRequest(); - request.setArtifact(artifact); - request.setRepositories(Collections.emptyList()); - result = repoSystem.resolveArtifact(repoSession, request); - } catch (Exception e) { - MojoExecutionException ex = new MojoExecutionException("Cannot resolve dependency"); - ex.initCause(e); - throw ex; - } CeylonImportJarTool tool = new CeylonImportJarTool(); if (moduleImport.getDescriptor() != null) { tool.setDescriptor(moduleImport.getDescriptor()); @@ -115,16 +115,35 @@ public void execute() throws MojoExecutionException, MojoFailureException { } tool.setCwd(cwd); tool.setOut(out); - tool.setFile(result.getArtifact().getFile()); + try { + ArtifactResult result = fetch(dependency); + tool.setFile(result.getArtifact().getFile()); + } catch (Exception e) { + MojoExecutionException ex = new MojoExecutionException("Cannot resolve dependency"); + ex.initCause(e); + throw ex; + } + if (moduleImport.getSources()) { + try { + dependency.setClassifier("sources"); + ArtifactResult result = fetch(dependency); + tool.setSourceJarFile(result.getArtifact().getFile()); + } catch (ArtifactResolutionException e) { + // No sources + } catch (Exception e) { + MojoExecutionException ex = new MojoExecutionException("Cannot resolve dependency"); + ex.initCause(e); + throw ex; + } + } - // String moduleName = moduleImport.getName(); String moduleVersion = moduleImport.getVersion(); if (moduleName == null) { moduleName = dependency.getGroupId() + "." + dependency.getArtifactId(); } if (moduleVersion == null) { - moduleVersion = dependencyVersion; + moduleVersion = dependency.getVersion(); } ModuleSpec moduleSpec = new ModuleSpec(moduleName, moduleVersion); moduleSpecs.add(moduleSpec); diff --git a/src/main/java/com/redhat/ceylon/maven/ModuleImport.java b/src/main/java/com/redhat/ceylon/maven/ModuleImport.java index dfc6ac0..a176e32 100644 --- a/src/main/java/com/redhat/ceylon/maven/ModuleImport.java +++ b/src/main/java/com/redhat/ceylon/maven/ModuleImport.java @@ -14,6 +14,7 @@ public class ModuleImport { private String name; private String version; private File descriptor; + private boolean sources = true; public Dependency getDependency() { return dependency; @@ -54,4 +55,12 @@ public File getDescriptor() { public void setDescriptor(File descriptor) { this.descriptor = descriptor; } + + public boolean getSources() { + return sources; + } + + public void setSources(boolean sources) { + this.sources = sources; + } }