-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working IT cases with proper manifest basic entries
Showing
15 changed files
with
246 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
plug-api/src/main/java/pl/wavesoftware/plugs/api/PlugsVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.api; | ||
|
||
import pl.wavesoftware.eid.exceptions.EidIllegalArgumentException; | ||
|
||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.jar.Manifest; | ||
|
||
import static pl.wavesoftware.eid.utils.EidExecutions.tryToExecute; | ||
import static pl.wavesoftware.eid.utils.EidPreconditions.checkNotNull; | ||
import static pl.wavesoftware.eid.utils.EidPreconditions.checkState; | ||
|
||
public final class PlugsVersion { | ||
|
||
private PlugsVersion() { | ||
// not reachable | ||
} | ||
|
||
public static String getVersion() { | ||
Optional<String> maybeVersion = | ||
Optional.ofNullable( | ||
PlugsVersion.class.getPackage().getImplementationVersion() | ||
); | ||
return checkNotNull( | ||
maybeVersion.orElseGet(PlugsVersion::manuallyRead), | ||
"20190325:202509" | ||
); | ||
} | ||
|
||
static String manuallyRead() { | ||
List<URL> urls = Collections.list(tryToExecute( | ||
() -> PlugsVersion.class | ||
.getClassLoader() | ||
.getResources("META-INF/MANIFEST.MF"), | ||
"20190325:205203" | ||
)); | ||
checkState(!urls.isEmpty(), "20190325:205809"); | ||
URL location = PlugsVersion.class.getProtectionDomain().getCodeSource().getLocation(); | ||
URL resource = urls.stream() | ||
.filter(url -> url.toString().contains(location.toString())) | ||
.findFirst() | ||
.orElseThrow(() -> new EidIllegalArgumentException("20190325:205648")); | ||
InputStream inputStream = checkNotNull( | ||
tryToExecute(resource::openStream, "20190325:205720"), | ||
"20190325:204807" | ||
); | ||
Manifest manifest = tryToExecute( | ||
() -> new Manifest(inputStream), | ||
"20190325:204433" | ||
); | ||
return manifest.getMainAttributes() | ||
.getValue("Implementation-Version"); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
plug-api/src/test/java/pl/wavesoftware/plugs/api/PlugsVersionIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.api; | ||
|
||
import com.github.zafarkhaja.semver.Version; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class PlugsVersionIT { | ||
|
||
private static final Version BASE = Version.forIntegers(0, 0, 0); | ||
|
||
@Test | ||
void getVersion() { | ||
Version version = Version.valueOf(PlugsVersion.getVersion()); | ||
|
||
assertThat(version.greaterThanOrEqualTo(BASE)).isTrue(); | ||
} | ||
|
||
@Test | ||
void manually() { | ||
Version version = Version.valueOf(PlugsVersion.manuallyRead()); | ||
|
||
assertThat(version.greaterThanOrEqualTo(BASE)).isTrue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...rc/main/java/pl/wavesoftware/plugs/tools/packager/core/jar/SkipManifestMfTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 org.apache.commons.compress.archivers.jar.JarArchiveEntry; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
final class SkipManifestMfTransformer implements EntryTransformer { | ||
|
||
private final EntryTransformer delegate = new IdentityEntryTransformer(); | ||
|
||
@Override | ||
@Nullable | ||
public JarArchiveEntry transform(JarArchiveEntry jarEntry) { | ||
if (jarEntry.getName().equals("META-INF/MANIFEST.MF")) { | ||
return null; | ||
} | ||
return delegate.transform(jarEntry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters