Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*/
package org.apache.maven.shared.dependency.analyzer.asm;

import java.util.Arrays;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
Expand Down Expand Up @@ -157,4 +160,14 @@ private void addTypeSignature(final String signature) {
new SignatureReader(signature).acceptType(signatureVisitor);
}
}

@Override
public void visitInvokeDynamicInsn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insn --> Instruction
I had to think about this one to figure it out.
In general, avoid abbreviations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming is controlled by ASM. This class extends MethodVisitor from ASM.

String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
Arrays.stream(bootstrapMethodArguments)
.filter(Type.class::isInstance)
.map(Type.class::cast)
.map(Type::getDescriptor)
.forEach(resultCollector::addMethodDesc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*/
package org.apache.maven.shared.dependency.analyzer.asm;

import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;

import org.apache.maven.shared.dependency.analyzer.DependencyAnalyzer;
Expand All @@ -40,4 +43,12 @@ void test() throws Exception {

assertThat(result).isNotEmpty();
}

@Test
void verify_implicit_class_reference_included_in_used_classes() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming convention seems wonky here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snake case is a habit, I find it more readable. I have no strong opinions. If it should be changed to camelCase then let me know and I will update.

Please also check if my logic is sound. I am no expert in ASM and byte code. Naming is easily fixed.

Path file = Paths.get("target/test-classes/org/apache/maven/shared/dependency/analyzer/testcases/analyze");

Set<String> result = analyzer.analyze(file.toUri().toURL());
assertThat(result).contains("org.apache.maven.artifact.resolver.ArtifactResolutionRequest");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,14 @@ void testVisitMaxs() {
assertThat(resultCollector.getDependencies()).isEmpty();
}

// visitInvokeDynamicInsn tests -------------------------------------------
@Test
void testVisitInvokeDynamic() {
Type type = Type.getType("(La/b/C;)V");
mv.visitInvokeDynamicInsn("a", "", null, type);
assertThat(resultCollector.getDependencies()).contains("a.b.C");
}

private void assertVisitor(Object actualVisitor) {
// assertEquals( visitor, actualVisitor );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.maven.shared.dependency.analyzer.testcases.analyze;

import org.apache.maven.shared.dependency.analyzer.testcases.prepare.Prepare;

/**
* Class to be analyzed in unit test.
* <p>
* The handler method in {@link Prepare} takes an implicit Consumer&lt;ArtifactResolutionRequest&gt; argument. Analyze
* this class to verify the implicit reference.
*/
public class AnalyzedClass {

public void useFirst() {
new Prepare().handler(this::doNothing);
}

private void doNothing(final Object object) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.maven.shared.dependency.analyzer.testcases.prepare;

import java.util.function.Consumer;

import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;

/**
* Class to be used for verifying that analyzer picks up usage of classes with no import.
*/
public class Prepare {

public void handler(Consumer<ArtifactResolutionRequest> consumer) {
ResolutionErrorHandler resolutionErrorHandler = (request, result) -> {
consumer.accept(request);
};
}
}