Skip to content

Commit

Permalink
Merge branch 'develop' (Bombe 0.4.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed Feb 28, 2020
2 parents dc6ba55 + ee4759c commit cb6c448
Show file tree
Hide file tree
Showing 37 changed files with 571 additions and 694 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ language: java
jdk:
- oraclejdk8

script: ./gradlew build
after_success: '[[ "$TRAVIS_BRANCH" = "develop" ]] && ./gradlew uploadArchives'
script:
- ./gradlew build
- ./gradlew codeCoverageReport
after_success:
- '[[ "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" = "develop" ]] && ./gradlew uploadArchives'
- bash <(curl -s https://codecov.io/bash)

# Ugh.
notifications:
Expand Down
4 changes: 0 additions & 4 deletions bombe-asm/build.gradle

This file was deleted.

2 changes: 0 additions & 2 deletions bombe-asm/gradle.properties

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions bombe-jar/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies {
compile project(':bombe')
compileOnly "org.ow2.asm:asm-commons:$asmVersion"
testCompile "org.ow2.asm:asm-commons:$asmVersion"
}
2 changes: 2 additions & 0 deletions bombe-jar/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = Bombe-Jar
description = Base classes for representing entries in a Jar file.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.cadixdev.bombe.asm.jar;
package org.cadixdev.bombe.jar.asm;

import org.cadixdev.bombe.jar.JarClassEntry;
import org.cadixdev.bombe.jar.JarEntryTransformer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,33 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.cadixdev.bombe.test.jar;
package org.cadixdev.bombe.jar.test

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.cadixdev.bombe.jar.AbstractJarEntry;
import org.cadixdev.bombe.jar.JarResourceEntry;
import org.junit.jupiter.api.Test;
import org.cadixdev.bombe.jar.AbstractJarEntry
import org.cadixdev.bombe.jar.JarResourceEntry
import spock.lang.Specification

/**
* Unit tests pertaining to the jar entry classes.
* Tests for Bombe's jar tooling.
*/
public final class JarEntryTests {

private static final AbstractJarEntry PACKAGED_ENTRY = new JarResourceEntry("pack/beep.boop", 0, null);
private static final AbstractJarEntry ROOT_ENTRY = new JarResourceEntry("beep.boop", 0, null);

@Test
public void packageName() {
assertEquals("pack", PACKAGED_ENTRY.getPackage());
assertEquals("", ROOT_ENTRY.getPackage());
}

@Test
public void simpleName() {
assertEquals("beep", PACKAGED_ENTRY.getSimpleName());
assertEquals("beep", ROOT_ENTRY.getSimpleName());
}

@Test
public void extension() {
assertEquals("boop", PACKAGED_ENTRY.getExtension());
assertEquals("boop", ROOT_ENTRY.getExtension());
class JarEntrySpec extends Specification {

private static final AbstractJarEntry PACKAGED_ENTRY = new JarResourceEntry("pack/beep.boop", 0, null)
private static final AbstractJarEntry ROOT_ENTRY = new JarResourceEntry("beep.boop", 0, null)

def "reads name correctly"(final AbstractJarEntry entry,
final String packageName,
final String simpleName,
final String extension) {
expect:
entry.package == packageName
entry.simpleName == simpleName
entry.extension == extension

where:
entry | packageName | simpleName | extension
PACKAGED_ENTRY | 'pack' | 'beep' | 'boop'
ROOT_ENTRY | '' | 'beep' | 'boop'
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,33 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.cadixdev.bombe.test.jar;
package org.cadixdev.bombe.jar.test

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.cadixdev.bombe.jar.ServiceProviderConfiguration
import spock.lang.Specification

import org.cadixdev.bombe.jar.ServiceProviderConfiguration;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets

/**
* Unit tests pertaining to {@link ServiceProviderConfiguration}.
* Test for Bombe's ServiceProviderConfiguration.
*/
public final class ServiceProviderConfigurationTests {

@Test
public void readConfig() throws IOException {
final ServiceProviderConfiguration config = new ServiceProviderConfiguration("demo.Demo");
try (final InputStream is =
ServiceProviderConfigurationTests.class.getResourceAsStream("/demo.Demo")) {
config.read(is);
}
assertEquals(2, config.getProviders().size());
assertTrue(config.getProviders().contains("demo.DemoImpl"), "Provider not present!");
assertTrue(config.getProviders().contains("demo.DemoAltImpl"), "Provider not present!");
class ServiceProviderConfigurationSpec extends Specification {

private static final String CONTENTS = '''
demo.DemoImpl
demo.DemoAltImpl
'''

def "reads configuration"() {
given:
def bais = new ByteArrayInputStream(CONTENTS.getBytes(StandardCharsets.UTF_8))
def config = new ServiceProviderConfiguration('demo.Demo')
config.read(bais)

expect:
config.providers.size() == 2
config.providers.contains('demo.DemoImpl')
config.providers.contains('demo.DemoAltImpl')
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2018, Jamie Mansfield <https://jamiemansfield.me/>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.cadixdev.bombe.jar.test.asm

import org.cadixdev.bombe.jar.asm.JarEntryRemappingTransformer
import org.cadixdev.bombe.jar.JarClassEntry
import org.cadixdev.bombe.jar.JarManifestEntry
import org.cadixdev.bombe.jar.JarServiceProviderConfigurationEntry
import org.cadixdev.bombe.jar.ServiceProviderConfiguration
import org.objectweb.asm.ClassReader
import org.objectweb.asm.ClassWriter
import org.objectweb.asm.Opcodes
import org.objectweb.asm.commons.Remapper
import org.objectweb.asm.tree.ClassNode
import spock.lang.Specification

import java.util.jar.Attributes
import java.util.jar.Manifest

/**
* Tests for Bombe's ASM tooling for the jar tooling.
*/
class JarEntryRemappingTransformerSpec extends Specification {

private static final Remapper REMAPPER = new Remapper() {
@Override
String map(final String internalName) {
if ('a' == internalName) return 'pkg/Demo'
if ('b' == internalName) return 'pkg/DemoTwo'
return internalName
}
}
private static final JarEntryRemappingTransformer TRANSFORMER =
new JarEntryRemappingTransformer(REMAPPER)

def "remaps class"() {
given:
// Create a test class
def obf = new ClassWriter(0)
obf.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, 'a', null, 'java/lang/Object', null)

// Run it through the transformer
def entry = TRANSFORMER.transform(new JarClassEntry('a.class', 0, obf.toByteArray()))

// Use a ClassNode for convenience
def node = new ClassNode()
def reader = new ClassReader(entry.contents)
reader.accept(node, 0)

expect:
entry.name == 'pkg/Demo.class'
node.name == 'pkg/Demo'
}

def "remaps manifest"() {
given:
// Create a test Manifest
def obf = new Manifest()
obf.with {
mainAttributes[name('Manifest-Version')] = '1.0'
mainAttributes[name('Main-Class')] = 'a'
}

// Run it through the transformer
def deobf = TRANSFORMER.transform(new JarManifestEntry(0, obf)).manifest

expect:
deobf.mainAttributes[name('Main-Class')] == 'pkg.Demo'
}

def "remaps service config"() {
given:
// Create a test service config
def obf = new ServiceProviderConfiguration('a', ['b'])

// Run it through the transformer
def deobf = TRANSFORMER.transform(new JarServiceProviderConfigurationEntry(0, obf)).config

expect:
deobf.service == 'pkg.Demo'
deobf.providers.size() == 1
deobf.providers == ['pkg.DemoTwo']
}

static def name(final String name) {
new Attributes.Name(name)
}

}
3 changes: 3 additions & 0 deletions bombe/build.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
dependencies {
compile "me.jamiemansfield:string:$stringVersion"
compileOnly "org.ow2.asm:asm-commons:$asmVersion"
testCompile "org.ow2.asm:asm-commons:$asmVersion"
}
Loading

0 comments on commit cb6c448

Please sign in to comment.