Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing tests. Apply integration tests in Gradle if Maven profi…
…le is set.
- Loading branch information
Showing
42 changed files
with
1,651 additions
and
21 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
2 changes: 1 addition & 1 deletion
2
byte-buddy-gradle-plugin/gradle/wrapper/gradle-wrapper.properties
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
114 changes: 114 additions & 0 deletions
114
byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddyLogHandler.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,114 @@ | ||
package net.bytebuddy.build.gradle; | ||
|
||
import org.gradle.api.Project; | ||
|
||
import java.util.logging.Handler; | ||
import java.util.logging.LogRecord; | ||
import java.util.logging.Logger; | ||
import java.util.logging.SimpleFormatter; | ||
|
||
/** | ||
* A log handler for only printing Byte Buddy specific log-messages if debug logging is enabled for a plugin. | ||
*/ | ||
public class ByteBuddyLogHandler extends Handler { | ||
|
||
private final Project project; | ||
|
||
/** | ||
* The Byte Buddy logger target. | ||
*/ | ||
private final Logger logger; | ||
|
||
/** | ||
* {@code true} if parent handler delegation was originally enabled. | ||
*/ | ||
private final boolean useParentHandlers; | ||
|
||
/** | ||
* Creates a new log handler. | ||
* | ||
* @param log The Maven logging target. | ||
* @param logger The Byte Buddy logger target. | ||
* @param useParentHandlers {@code true} if parent handler delegation was originally enabled. | ||
*/ | ||
protected ByteBuddyLogHandler(Project project, Logger logger, boolean useParentHandlers) { | ||
this.project = project; | ||
this.logger = logger; | ||
this.useParentHandlers = useParentHandlers; | ||
setFormatter(new SimpleFormatter()); | ||
} | ||
|
||
/** | ||
* Initializes the Byte Buddy log handler. | ||
* | ||
* @param log The Maven logging target. | ||
* @return The registered log handler. | ||
*/ | ||
public static ByteBuddyLogHandler initialize(Project project) { | ||
Logger logger = Logger.getLogger("net.bytebuddy"); | ||
ByteBuddyLogHandler handler = new ByteBuddyLogHandler(project, logger, logger.getUseParentHandlers()); | ||
try { | ||
logger.setUseParentHandlers(false); | ||
logger.addHandler(handler); | ||
} catch (SecurityException exception) { | ||
project.getLogger().warn("Cannot configure Byte Buddy logging", exception); | ||
} | ||
return handler; | ||
} | ||
|
||
/** | ||
* Resets the configuration to its original state. | ||
*/ | ||
public void reset() { | ||
try { | ||
logger.setUseParentHandlers(useParentHandlers); | ||
logger.removeHandler(this); | ||
} catch (SecurityException exception) { | ||
project.getLogger().warn("Cannot configure Byte Buddy logging", exception); | ||
} | ||
} | ||
|
||
@Override | ||
public void publish(LogRecord record) { | ||
if (project.getLogger().isDebugEnabled()) { | ||
project.getLogger().debug(getFormatter().format(record)); | ||
} | ||
} | ||
|
||
@Override | ||
public void flush() { | ||
/* do nothing */ | ||
} | ||
|
||
@Override | ||
public void close() { | ||
/* do nothing */ | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) return true; | ||
if (object == null || getClass() != object.getClass()) return false; | ||
ByteBuddyLogHandler that = (ByteBuddyLogHandler) object; | ||
return useParentHandlers == that.useParentHandlers | ||
&& logger.equals(that.logger) | ||
&& project.equals(that.project); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = project.hashCode(); | ||
result = 31 * result + logger.hashCode(); | ||
result = 31 * result + (useParentHandlers ? 1 : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ByteBuddyLogHandler{" + | ||
"project=" + project + | ||
" ,logger=" + logger + | ||
" ,useParentHandlers=" + useParentHandlers + | ||
'}'; | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
...src/test/java/net/bytebuddy/build/gradle/AbstractUserConfigurationPrefixIterableTest.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,45 @@ | ||
package net.bytebuddy.build.gradle; | ||
|
||
import net.bytebuddy.test.utility.MockitoRule; | ||
import net.bytebuddy.test.utility.ObjectPropertyAssertion; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
import org.mockito.Mock; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class AbstractUserConfigurationPrefixIterableTest { | ||
|
||
@Rule | ||
public TestRule mockitoRule = new MockitoRule(this); | ||
|
||
@Mock | ||
private File primary, other; | ||
|
||
@Test | ||
public void testIteration() throws Exception { | ||
Iterator<? extends File> iterator = new AbstractUserConfiguration.PrefixIterable(primary, Collections.singleton(other)).iterator(); | ||
assertThat(iterator.hasNext(), is(true)); | ||
assertThat(iterator.next(), is(primary)); | ||
assertThat(iterator.hasNext(), is(true)); | ||
assertThat(iterator.next(), is(other)); | ||
assertThat(iterator.hasNext(), is(false)); | ||
} | ||
|
||
@Test(expected = UnsupportedOperationException.class) | ||
public void testRemoval() throws Exception { | ||
new AbstractUserConfiguration.PrefixIterable(primary, Collections.<File>emptySet()).iterator().remove(); | ||
} | ||
|
||
@Test | ||
public void testObjectProperties() throws Exception { | ||
ObjectPropertyAssertion.of(AbstractUserConfiguration.PrefixIterable.class).applyBasic(); | ||
ObjectPropertyAssertion.of(AbstractUserConfiguration.PrefixIterable.PrefixIterator.class).applyBasic(); | ||
} | ||
} |
Oops, something went wrong.