Skip to content

Commit

Permalink
issue #80
Browse files Browse the repository at this point in the history
add support of javac option --module-path
  • Loading branch information
bsorrentino committed Apr 16, 2020
1 parent 2e0db25 commit 8d6d9c3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.tools.JavaCompiler.CompilationTask;
Expand Down Expand Up @@ -358,6 +360,8 @@ private String buildProcessor()
return result.toString();
}

protected abstract java.util.Set<String> getResourcesElements( java.util.Set<String> result );

protected abstract java.util.Set<String> getClasspathElements( java.util.Set<String> result );

private String buildCompileSourcepath( Consumer<String> onSuccess) {
Expand All @@ -379,7 +383,11 @@ private String buildCompileClasspath()
{

final java.util.Set<String> pathElements = new java.util.LinkedHashSet<>();


getResourcesElements(pathElements);

getClasspathElements(pathElements);

if( pluginArtifacts!=null ) {

for( Artifact a : pluginArtifacts ) {
Expand All @@ -389,13 +397,13 @@ private String buildCompileClasspath()
java.io.File f = a.getFile();

if( f!=null ) pathElements.add( a.getFile().getAbsolutePath() );

}

}
}

getClasspathElements(pathElements);



final StringBuilder result = new StringBuilder();

for( String elem : pathElements ) {
Expand All @@ -404,6 +412,13 @@ private String buildCompileClasspath()
return result.toString();
}

private String buildModulePath()
{

return getClasspathElements(new java.util.LinkedHashSet<>())
.stream()
.collect(Collectors.joining( File.pathSeparator) );
}

/**
*
Expand Down Expand Up @@ -557,7 +572,10 @@ private void executeWithExceptionsHandled() throws Exception

options.add("-cp");
options.add(compileClassPath);


options.add("--module-path");
options.add( buildModulePath() );

buildCompileSourcepath( sourcepath -> {
options.add("-sourcepath");
options.add(sourcepath);
Expand Down Expand Up @@ -586,6 +604,10 @@ private void executeWithExceptionsHandled() throws Exception
options.add( releaseVersion );
}

options.add("-source");
options.add("9");
options.add("-target");
options.add("9");

if( getLog().isDebugEnabled() ) {
for (String option : options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.File;
import java.util.List;
import java.util.Set;

import org.apache.maven.model.Resource;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -94,17 +96,22 @@ public java.util.Set<File> getSourceDirectories( final java.util.Set<File> resul
}

@Override
@SuppressWarnings("unchecked")
protected java.util.Set<String> getClasspathElements( final java.util.Set<String> result) {

List<Resource> resources = project.getResources();
protected Set<String> getResourcesElements(Set<String> result) {
final List<Resource> resources = project.getResources();

if( resources!=null ) {
for( Resource r : resources ) {
result.add(r.getDirectory());
}
}

return result;
}

@Override
@SuppressWarnings("unchecked")
protected java.util.Set<String> getClasspathElements( final java.util.Set<String> result) {

result.addAll( classpathElements );

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.io.File;
import java.util.List;
import java.util.Set;

import org.apache.maven.model.Resource;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -92,10 +94,8 @@ public java.util.Set<File> getSourceDirectories( final java.util.Set<File> resul
return result;
}


@SuppressWarnings("unchecked")
@Override
protected java.util.Set<String> getClasspathElements( final java.util.Set<String> result ) {
protected Set<String> getResourcesElements(Set<String> result) {
final List<Resource> resources = project.getTestResources();

if( resources!=null ) {
Expand All @@ -104,6 +104,13 @@ protected java.util.Set<String> getClasspathElements( final java.util.Set<String
}
}

return result;
}

@SuppressWarnings("unchecked")
@Override
protected java.util.Set<String> getClasspathElements( final java.util.Set<String> result ) {

result.addAll( classpathElements );

return result;
Expand Down

0 comments on commit 8d6d9c3

Please sign in to comment.