diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/filter/MavenFilter.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/filter/MavenFilter.java index c068643..93ed40c 100644 --- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/filter/MavenFilter.java +++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/filter/MavenFilter.java @@ -42,10 +42,9 @@ final class MavenFilter implements Filter { public Set filterDependencies(Set dependencies) throws RepackageFailed { try { - Set delta = HashSet.ofAll( + return HashSet.ofAll( filters.filter(dependencies.map(artifactMapper::mavenize).toJavaSet()) ).map(artifactMapper::generalize); - return dependencies.retainAll(delta); } catch (ArtifactFilterException ex) { throw new RepackageFailed( "Can't filter Maven dependencies using provided filters", 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 6ea8416..dd60134 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,6 +16,7 @@ package pl.wavesoftware.plugs.tools.maven.plugin.mapper; +import org.apache.maven.model.Dependency; import pl.wavesoftware.plugs.tools.packager.core.model.Artifact; /** @@ -25,4 +26,5 @@ public interface ArtifactMapper { Artifact generalize(org.apache.maven.artifact.Artifact artifact); org.apache.maven.artifact.Artifact mavenize(Artifact artifact); + Artifact map(Dependency 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 298b5d7..a0e46e5 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,11 @@ package pl.wavesoftware.plugs.tools.maven.plugin.mapper; +import org.apache.maven.model.Dependency; +import org.apache.maven.repository.RepositorySystem; import pl.wavesoftware.plugs.tools.packager.core.model.Artifact; +import javax.inject.Inject; import javax.inject.Named; /** @@ -26,6 +29,14 @@ */ @Named final class ArtifactMapperImpl implements ArtifactMapper { + + private final RepositorySystem repositorySystem; + + @Inject + ArtifactMapperImpl(RepositorySystem repositorySystem) { + this.repositorySystem = repositorySystem; + } + @Override public Artifact generalize(org.apache.maven.artifact.Artifact artifact) { return new MavenArtifact(artifact); @@ -36,8 +47,16 @@ 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); + } } 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 224bbd8..01395ed 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,6 +19,7 @@ import io.vavr.Lazy; import io.vavr.collection.HashSet; import io.vavr.collection.Set; +import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; import pl.wavesoftware.plugs.tools.packager.core.model.Artifact; import pl.wavesoftware.plugs.tools.packager.core.model.Project; @@ -88,19 +89,19 @@ public Set imports() { private Set calculateDependencies() { return HashSet - .ofAll(mavenProject.getArtifacts()) + .ofAll(mavenProject.getDependencies()) .reject(MavenBackedProject::hasProvidedScope) - .map(artifactMapper::generalize); + .map(artifactMapper::map); } private Set calculateImports() { return HashSet - .ofAll(mavenProject.getArtifacts()) + .ofAll(mavenProject.getDependencies()) .filter(MavenBackedProject::hasProvidedScope) - .map(artifactMapper::generalize); + .map(artifactMapper::map); } - private static boolean hasProvidedScope(org.apache.maven.artifact.Artifact artifact) { - return artifact.getScope().equals(org.apache.maven.artifact.Artifact.SCOPE_SYSTEM); + private static boolean hasProvidedScope(Dependency dependency) { + return dependency.getScope().equals(org.apache.maven.artifact.Artifact.SCOPE_PROVIDED); } } 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 new file mode 100644 index 0000000..54c3ead --- /dev/null +++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenDependency.java @@ -0,0 +1,68 @@ +/* + * 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/MavenLibrariesFactory.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenLibrariesFactory.java index e1e8a53..c21b20f 100644 --- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenLibrariesFactory.java +++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/mapper/MavenLibrariesFactory.java @@ -44,7 +44,6 @@ final class MavenLibrariesFactory implements LibrariesFactory { public Libraries create(Set artifacts, Logger logger) { return new MavenLibraries( artifacts.map(artifactMapper::mavenize), - null, logger ); } diff --git a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/model/MavenLibraries.java b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/model/MavenLibraries.java index 8e2468e..bc3d97c 100644 --- a/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/model/MavenLibraries.java +++ b/tools/plugs-maven-plugin/src/main/java/pl/wavesoftware/plugs/tools/maven/plugin/model/MavenLibraries.java @@ -20,17 +20,14 @@ import io.vavr.collection.HashSet; import io.vavr.collection.Map; import io.vavr.collection.Set; -import io.vavr.collection.Traversable; import io.vavr.control.Option; import org.apache.maven.artifact.Artifact; -import org.apache.maven.model.Dependency; import org.slf4j.Logger; import pl.wavesoftware.plugs.tools.packager.core.model.Libraries; import pl.wavesoftware.plugs.tools.packager.core.model.Library; import pl.wavesoftware.plugs.tools.packager.core.model.LibraryCallback; import pl.wavesoftware.plugs.tools.packager.core.model.LibraryScope; -import javax.annotation.Nullable; import java.io.IOException; /** @@ -51,17 +48,13 @@ public final class MavenLibraries implements Libraries { .put(Artifact.SCOPE_SYSTEM, LibraryScope.PROVIDED); private final Set artifacts; - @Nullable - private final Traversable unpacks; private final Logger logger; public MavenLibraries( Set artifacts, - @Nullable Traversable unpacks, Logger logger ) { this.artifacts = artifacts; - this.unpacks = unpacks; this.logger = logger; } @@ -82,25 +75,12 @@ public void doWithLibraries(LibraryCallback callback) throws IOException { callback.library(new Library( name.toString(), artifact.getFile(), - scopeOption.get(), - isUnpackRequired(artifact) + scopeOption.get() )); } } } - private boolean isUnpackRequired(Artifact artifact) { - if (this.unpacks != null) { - for (Dependency unpack : this.unpacks) { - if (artifact.getGroupId().equals(unpack.getGroupId()) - && artifact.getArtifactId().equals(unpack.getArtifactId())) { - return true; - } - } - } - return false; - } - private static Set getDuplicates(Set artifacts) { java.util.Set duplicates = new java.util.HashSet<>(); java.util.Set seen = new java.util.HashSet<>(); 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 9629ba2..1d580ac 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 @@ -167,7 +167,7 @@ private void repackage( "Can't write libraries to a destination jar, {}", destination ); - tring(() -> writer.writeEntries(sourceJar, writeableLibraries)).or( + tring(() -> writer.writeEntries(sourceJar)).or( "Can't rewrite source jar into destination jar: {}", destination ); diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/ArchiveWriter.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/ArchiveWriter.java index adcdb25..22c0444 100644 --- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/ArchiveWriter.java +++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/ArchiveWriter.java @@ -73,13 +73,7 @@ void writeNestedLibrary( void writeEntries( JarFile jarFile, - UnpackHandler unpackHandler - ) throws IOException; - - void writeEntries( - JarFile jarFile, - EntryTransformer entryTransformer, - UnpackHandler unpackHandler + EntryTransformer entryTransformer ) throws IOException; void addListener( diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/FileUtils.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/FileUtils.java index f3d64dd..b92c19a 100644 --- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/FileUtils.java +++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/FileUtils.java @@ -19,16 +19,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.WillNotClose; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.security.DigestInputStream; -import java.security.MessageDigest; - -import static pl.wavesoftware.eid.utils.EidExecutions.tryToExecute; /** * Utilities for manipulating files and directories in Spring Boot tooling. @@ -41,7 +35,6 @@ final class FileUtils { private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class); - private static final int BUFFER_4K = 4098; private static final byte[] ZIP_FILE_HEADER = new byte[] { 'P', 'K', 3, 4 }; private FileUtils() { @@ -70,40 +63,4 @@ private static boolean isZip(InputStream inputStream) throws IOException { return true; } - /** - * Generate a SHA.1 Hash for a given file. - * @param file the file to hash - * @return the hash value as a String - * @throws IOException if the file cannot be read - */ - static String sha256Hash(File file) throws IOException { - MessageDigest digest = tryToExecute( - () -> MessageDigest.getInstance("SHA-256"), - "20190115:225947" - ); - try (DigestInputStream inputStream = newDigestInputStream(file, digest)) { - byte[] buffer = new byte[BUFFER_4K]; - //noinspection StatementWithEmptyBody - while (inputStream.read(buffer) != -1) { - // Read the entire stream - } - return bytesToHex(inputStream.getMessageDigest().digest()); - } - } - - @WillNotClose - private static DigestInputStream newDigestInputStream( - File file, - MessageDigest digest - ) throws FileNotFoundException { - return new DigestInputStream(new FileInputStream(file), digest); - } - - private static String bytesToHex(byte[] bytes) { - StringBuilder hex = new StringBuilder(); - for (byte b : bytes) { - hex.append(String.format("%02x", b)); - } - return hex.toString(); - } } diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/JarWriter.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/JarWriter.java index 37d541c..bed7483 100644 --- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/JarWriter.java +++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/JarWriter.java @@ -26,8 +26,6 @@ import javax.annotation.Nullable; import javax.annotation.WillClose; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -58,7 +56,6 @@ public final class JarWriter implements ArchiveWriter, AutoCloseable { private static final Logger LOGGER = LoggerFactory.getLogger(JarWriter.class); - private static final UnpackHandler NEVER_UNPACK = new NeverUnpackHandler(); private final JarArchiveOutputStream jarOutput; private final Set writtenEntries = new HashSet<>(); @@ -104,8 +101,7 @@ public void writeNestedLibrary( new CrcAndSize(file).setupStoredEntry(entry); writeEntry( entry, - new InputStreamEntryWriter(new FileInputStream(file), true), - new LibraryUnpackHandler(library) + new InputStreamEntryWriter(new FileInputStream(file), true) ); LibraryHasBeenWritten event = new LibraryHasBeenWritten(library); for (ArchiveWriterListener listener : listeners.get(LibraryHasBeenWritten.class)) { @@ -118,19 +114,13 @@ public void writeNestedLibrary( @Override public void writeEntries(JarFile jarFile) throws IOException { - this.writeEntries(jarFile, new SkipManifestMfTransformer(), NEVER_UNPACK); - } - - @Override - public void writeEntries(JarFile jarFile, UnpackHandler unpackHandler) throws IOException { - this.writeEntries(jarFile, new SkipManifestMfTransformer(), unpackHandler); + this.writeEntries(jarFile, new SkipManifestMfTransformer()); } @Override public void writeEntries( JarFile jarFile, - EntryTransformer entryTransformer, - UnpackHandler unpackHandler + EntryTransformer entryTransformer ) throws IOException { Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { @@ -141,7 +131,7 @@ public void writeEntries( EntryWriter entryWriter = new InputStreamEntryWriter(inputStream, true); JarArchiveEntry transformedEntry = entryTransformer.transform(entry); if (transformedEntry != null) { - writeEntry(transformedEntry, entryWriter, unpackHandler); + writeEntry(transformedEntry, entryWriter); } } } @@ -211,26 +201,17 @@ public void close() throws IOException { this.jarOutput.close(); } - private void writeEntry( - JarArchiveEntry entry, - EntryWriter entryWriter - ) throws IOException { - writeEntry(entry, entryWriter, NEVER_UNPACK); - } - /** * Perform the actual write of a {@link JarEntry}. All other write methods delegate to * this one. * * @param entry the entry to write * @param entryWriter the entry writer or {@code null} if there is no content - * @param unpackHandler handles possible unpacking for the entry * @throws IOException in case of I/O errors */ private void writeEntry( JarArchiveEntry entry, - @Nullable EntryWriter entryWriter, - UnpackHandler unpackHandler + @Nullable EntryWriter entryWriter ) throws IOException { String parent = entry.getName(); boolean isDirectory = false; @@ -244,12 +225,11 @@ private void writeEntry( if (parent.lastIndexOf('/') != -1) { parent = parent.substring(0, parent.lastIndexOf('/') + 1); if (!parent.isEmpty()) { - writeEntry(new JarArchiveEntry(parent), null, unpackHandler); + writeEntry(new JarArchiveEntry(parent), null); } } if (this.writtenEntries.add(entry.getName())) { - entryWriter = addUnpackCommentIfNecessary(entry, entryWriter, unpackHandler); this.jarOutput.putArchiveEntry(entry); if (entryWriter != null) { entryWriter.write(this.jarOutput); @@ -265,21 +245,4 @@ private void writeEntry( } } - private static EntryWriter addUnpackCommentIfNecessary( - JarArchiveEntry entry, - @Nullable EntryWriter entryWriter, - UnpackHandler unpackHandler - ) throws IOException { - if (entryWriter == null || !unpackHandler.requiresUnpack(entry.getName())) { - return entryWriter; - } - ByteArrayOutputStream output = new ByteArrayOutputStream(); - entryWriter.write(output); - entry.setComment("UNPACK:" + unpackHandler.sha256Hash(entry.getName())); - return new InputStreamEntryWriter( - new ByteArrayInputStream(output.toByteArray()), - true - ); - } - } diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/LibraryUnpackHandler.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/LibraryUnpackHandler.java deleted file mode 100644 index d62d669..0000000 --- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/LibraryUnpackHandler.java +++ /dev/null @@ -1,45 +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.packager.core.jar; - -import pl.wavesoftware.plugs.tools.packager.core.model.Library; - -import java.io.IOException; - -/** - * @author Krzysztof Suszynski - * @since 0.1.0 - */ -final class LibraryUnpackHandler implements UnpackHandler { - - private final Library library; - - LibraryUnpackHandler(Library library) { - this.library = library; - } - - @Override - public boolean requiresUnpack(String name) { - return this.library.isUnpackRequired(); - } - - @Override - public String sha256Hash(String name) throws IOException { - return FileUtils.sha256Hash(this.library.getFile()); - } - -} diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/NeverUnpackHandler.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/NeverUnpackHandler.java deleted file mode 100644 index 3b4b2d7..0000000 --- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/NeverUnpackHandler.java +++ /dev/null @@ -1,35 +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.packager.core.jar; - -/** - * @author Krzysztof Suszynski - * @since 0.1.0 - */ -final class NeverUnpackHandler implements UnpackHandler { - - @Override - public boolean requiresUnpack(String name) { - return false; - } - - @Override - public String sha256Hash(String name) { - throw new UnsupportedOperationException("Not supported"); - } - -} diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/UnpackHandler.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/UnpackHandler.java deleted file mode 100644 index 9f41775..0000000 --- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/UnpackHandler.java +++ /dev/null @@ -1,32 +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.packager.core.jar; - -import java.io.IOException; - -/** - * An {@code UnpackHandler} determines whether or not unpacking is - * required and provides a SHA256 hash if required. - * - * @author Krzysztof Suszynski - * @since 0.1.0 - */ -interface UnpackHandler { - boolean requiresUnpack(String name); - - String sha256Hash(String name) throws IOException; -} diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/WritableLibraries.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/WritableLibraries.java index fa818d0..361b742 100644 --- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/WritableLibraries.java +++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/WritableLibraries.java @@ -32,7 +32,7 @@ * @author Krzysztof Suszynski * @since 0.1.0 */ -public final class WritableLibraries implements UnpackHandler { +public final class WritableLibraries { private final Map libraryEntryNames = new LinkedHashMap<>(); @@ -52,22 +52,6 @@ public WritableLibraries(Libraries libraries) throws IOException { }); } - @Override - public boolean requiresUnpack(String name) { - Library library = this.libraryEntryNames.get(name); - return library != null && library.isUnpackRequired(); - } - - @Override - public String sha256Hash(String name) throws IOException { - Library library = this.libraryEntryNames.get(name); - if (library == null) { - throw new IllegalArgumentException( - "No library found for entry name '" + name + "'"); - } - return FileUtils.sha256Hash(library.getFile()); - } - public void write(JarWriter writer) throws IOException { for (Map.Entry entry : this.libraryEntryNames.entrySet()) { writer.writeNestedLibrary( diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/CodeBlock.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/CodeBlock.java index 6229288..76ce3d2 100644 --- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/CodeBlock.java +++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/CodeBlock.java @@ -20,8 +20,7 @@ * A block of code to be executed */ @FunctionalInterface -public -interface CodeBlock { +public interface CodeBlock { /** * A simple execute command */ diff --git a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/Library.java b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/Library.java index 6bb5327..dad32f6 100644 --- a/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/Library.java +++ b/tools/plugs-packager-core/src/main/java/pl/wavesoftware/plugs/tools/packager/core/model/Library.java @@ -32,7 +32,6 @@ public final class Library { private final String name; private final File file; private final LibraryScope scope; - private final boolean unpackRequired; /** * Create a new {@link Library}. @@ -40,17 +39,7 @@ public final class Library { * @param scope the scope of the library */ public Library(File file, LibraryScope scope) { - this(file, scope, false); - } - - /** - * Create a new {@link Library}. - * @param file the source file - * @param scope the scope of the library - * @param unpackRequired if the library needs to be unpacked before it can be used - */ - public Library(File file, LibraryScope scope, boolean unpackRequired) { - this(null, file, scope, unpackRequired); + this(null, file, scope); } /** @@ -59,18 +48,15 @@ public Library(File file, LibraryScope scope, boolean unpackRequired) { * the file name * @param file the source file * @param scope the scope of the library - * @param unpackRequired if the library needs to be unpacked before it can be used */ public Library( @Nullable String name, File file, - LibraryScope scope, - boolean unpackRequired + LibraryScope scope ) { this.name = (name != null) ? name : file.getName(); this.file = file; this.scope = scope; - this.unpackRequired = unpackRequired; } /** @@ -97,12 +83,4 @@ public LibraryScope getScope() { return this.scope; } - /** - * Return if the file cannot be used directly as a nested jar and needs to be - * unpacked. - * @return if unpack is required - */ - public boolean isUnpackRequired() { - return this.unpackRequired; - } }