Skip to content

Commit

Permalink
set target directory for processSourceArtifacts to target/extracted-s…
Browse files Browse the repository at this point in the history
…ources
  • Loading branch information
bsorrentino committed Mar 6, 2021
1 parent fca883f commit 46fd8bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -783,7 +780,8 @@ private void executeWithExceptionsHandled() throws Exception
final UnzipService unzip = UnzipService.newInstance( getLog() );

if( fork ) {
processSourceArtifacts( artifact -> unzip.extractSourcesFromArtifactToTempDirectory( artifact, allSources ) );
processSourceArtifacts( artifact -> unzip.extractSourcesFromArtifactToTempDirectory( artifact, allSources,
Paths.get( project.getBuild().getDirectory(), "extracted-sources" ) ));
}
else {
processSourceArtifacts( artifact -> unzip.extractSourcesFromArtifact(artifact, allSources) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,35 @@ public final void extractSourcesFromArtifact(Artifact artifact, java.util.List<J
}
}

public final void extractSourcesFromArtifactToTempDirectory(Artifact artifact, java.util.List<JavaFileObject> allSources ) {
/**
*
* @param artifact
* @param allSources
* @param target target folder. if null a temporary folder is created
*/
public final void extractSourcesFromArtifactToTempDirectory(Artifact artifact, java.util.List<JavaFileObject> allSources, Path target ) {
requireNonNull( artifact, "artifact argument is null!");
requireNonNull( allSources, "allSources argument is null!");

final int size = allSources.size();

final File fileZip = artifact.getFile();

final Path root;
try {
root = Files.createTempDirectory(fileZip.getName());
if( target == null ) {
try {
target = Files.createTempDirectory(fileZip.getName());
} catch (IOException ex) {
log.warn("Problem creating temporary directory", ex);
return;
}
}
catch( IOException ex ) {
log.warn("Problem creating temporary directory", ex);
return;
else {
try {
target = Files.createDirectories( Paths.get( target.toString(), artifact.getArtifactId()) );
} catch (IOException ex) {
log.warn(format("Problem creating directory [%s]", target), ex);
return;
}
}

try( final ZipFile zipFile = new ZipFile(fileZip) ) {
Expand All @@ -167,7 +181,7 @@ public final void extractSourcesFromArtifactToTempDirectory(Artifact artifact, j

final ZipEntry zipEntry = entries.nextElement();

final Path newFile = Paths.get(root.toString(), zipEntry.getName());
final Path newFile = Paths.get(target.toString(), zipEntry.getName());

if (zipEntry.isDirectory()) {

Expand All @@ -194,6 +208,6 @@ public final void extractSourcesFromArtifactToTempDirectory(Artifact artifact, j

}

log.info( format( "[%d] sources succesfully extracted from artifact [%s] to:\n [%s]", allSources.size()-size, artifact, root));
log.info( format( "[%d] sources succesfully extracted from artifact [%s] to:\n [%s]", allSources.size()-size, artifact, target));
}
}

0 comments on commit 46fd8bc

Please sign in to comment.