Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Commit

Permalink
Fixed JENKINS-19383.
Browse files Browse the repository at this point in the history
"ldc <class>" is only valid after JavaSE 5, so the class file needs to have that version number
  • Loading branch information
kohsuke committed Oct 25, 2013
1 parent 9deadd5 commit c854abb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 12 additions & 2 deletions pom.xml
Expand Up @@ -27,14 +27,23 @@
<mkdir dir="target/test-classes/v2" />
<mkdir dir="target/test-classes/client" />

<path id="lib">
<fileset dir="target/lib" includes="*.jar" />
</path>

<!-- basic sanity. unmodified client and v1 should work as expected -->
<javac source="1.6" target="1.6" debug="true" srcdir="src/test/v1" destdir="target/test-classes/v1" />
<javac source="1.6" target="1.6" debug="true" srcdir="src/test/v1" destdir="target/test-classes/v1">
<classpath>
<path refid="lib" />
</classpath>
</javac>
<javac source="1.6" target="1.6" debug="true" srcdir="src/test/client" destdir="target/test-classes/client">
<classpath>
<pathelement path="target/classes" />
<pathelement path="target/test-classes/v1" />
<path refid="maven.compile.classpath" />
<path refid="maven.test.classpath" />
<path refid="lib" />
</classpath>
</javac>

Expand All @@ -43,6 +52,7 @@
<classpath>
<path refid="maven.compile.classpath" />
<pathelement path="target/classes" />
<path refid="lib" />
</classpath>
</javac>
</tasks>
Expand Down Expand Up @@ -76,7 +86,7 @@
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
<version>2.3.0</version>
<outputDirectory>target</outputDirectory>
<outputDirectory>target/lib</outputDirectory>
<destFileName>ivy.jar</destFileName>
</artifactItem>
</artifactItems>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jenkinsci/bytecode/Transformer.java
Expand Up @@ -67,6 +67,11 @@ public byte[] transform(final String className, byte[] image) {
final boolean[] modified = new boolean[1];

cr.accept(new ClassAdapter(cw) {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(Math.max(version,49), access, name, signature, superName, interfaces);
}

@Override
public MethodVisitor visitMethod(int access, final String methodName, final String methodDescriptor, String methodSignature, String[] exceptions) {
final MethodVisitor base = super.visitMethod(access, methodName, methodDescriptor, methodSignature, exceptions);
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/CompatibilityTest.java
Expand Up @@ -39,11 +39,14 @@ private void assertFieldType(Class<?> i, Class<?> type, String name) throws NoSu
private AntClassLoader createClassLoader(String v) throws IOException {
final Transformer t = new Transformer();
AntClassLoader cl = new AntClassLoader() {
final File outputDir = new File("target/modified-classes");
@Override
protected Class<?> defineClassFromData(File container, byte[] classData, String classname) throws IOException {
byte[] rewritten = t.transform(classname, classData);
if (rewritten!=classData) {
FileUtils.writeByteArrayToFile(new File(classname+".class"),rewritten);
File dst = new File(outputDir,classname.replace('.','/')+".class");
dst.getParentFile().mkdirs();
FileUtils.writeByteArrayToFile(dst,rewritten);
System.out.println("Modified "+classname);
}
return super.defineClassFromData(container, rewritten, classname);
Expand All @@ -52,7 +55,7 @@ protected Class<?> defineClassFromData(File container, byte[] classData, String

cl.addPathComponent(new File("target/test-classes/"+ v));
cl.addPathComponent(new File("target/test-classes/client"));
cl.addPathComponent(new File("target/ivy.jar"));
cl.addPathComponent(new File("target/lib/ivy.jar"));

t.loadRules(cl);

Expand Down

0 comments on commit c854abb

Please sign in to comment.