You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/09/11 19:19:40 UTC
[isis] 02/02: ISIS-2426: tooling: add java code analyzer
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 7372640fccc5a2806b1408f52f7de8c30bfdf579
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Sep 11 21:18:32 2020 +0200
ISIS-2426: tooling: add java code analyzer
---
tooling/javamodel/pom.xml | 101 +++++++++++++++++++++
.../tooling/javamodel/AnalyzerConfigFactory.java | 70 ++++++++++++++
.../isis/tooling/javamodel/test/AnalyzerTest.java | 98 ++++++++++++++++++++
tooling/pom.xml | 3 +-
4 files changed, 271 insertions(+), 1 deletion(-)
diff --git a/tooling/javamodel/pom.xml b/tooling/javamodel/pom.xml
new file mode 100644
index 0000000..7e8ee26
--- /dev/null
+++ b/tooling/javamodel/pom.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.isis.tooling</groupId>
+ <artifactId>isis-tooling</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>isis-tooling-javamodel</artifactId>
+
+ <name>Apache Isis Tooling - Java Model (Code Mining)</name>
+ <description>
+ Code mining library for Java bytecode introspection.
+ </description>
+
+ <properties>
+ <code-assert.version>0.9.13</code-assert.version>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.isis.tooling</groupId>
+ <artifactId>isis-tooling-commons</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>guru.nidi</groupId>
+ <artifactId>code-assert</artifactId>
+ <version>${code-assert.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.pinterest.ktlint</groupId>
+ <artifactId>ktlint-ruleset-standard</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.pinterest.ktlint</groupId>
+ <artifactId>ktlint-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.puppycrawl.tools</groupId>
+ <artifactId>checkstyle</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jul-to-slf4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jetbrains.kotlin</groupId>
+ <artifactId>kotlin-compiler-embeddable</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.h3xstream.findsecbugs</groupId>
+ <artifactId>findsecbugs-plugin</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>net.sourceforge.pmd</groupId>
+ <artifactId>pmd-java</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>io.gitlab.arturbosch.detekt</groupId>
+ <artifactId>detekt-rules</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>io.gitlab.arturbosch.detekt</groupId>
+ <artifactId>detekt-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.github.spotbugs</groupId>
+ <artifactId>spotbugs</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ </dependencies>
+
+</project>
+
+
diff --git a/tooling/javamodel/src/main/java/org/apache/isis/tooling/javamodel/AnalyzerConfigFactory.java b/tooling/javamodel/src/main/java/org/apache/isis/tooling/javamodel/AnalyzerConfigFactory.java
new file mode 100644
index 0000000..805efa8
--- /dev/null
+++ b/tooling/javamodel/src/main/java/org/apache/isis/tooling/javamodel/AnalyzerConfigFactory.java
@@ -0,0 +1,70 @@
+/*
+ * 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.isis.tooling.javamodel;
+
+import java.io.File;
+import java.util.EnumSet;
+import java.util.List;
+
+import org.apache.isis.tooling._infra._Files;
+
+import guru.nidi.codeassert.config.AnalyzerConfig;
+import guru.nidi.codeassert.config.Language;
+import guru.nidi.codeassert.config.ProjectLayout.Maven;
+import lombok.experimental.UtilityClass;
+
+@UtilityClass
+public class AnalyzerConfigFactory {
+
+ public static Maven maven(File projDir, Language ... languages) {
+ return new MavenExt(projDir, languages);
+ }
+
+ // -- HELPER
+
+ private static class AnalyzerConfigExt extends AnalyzerConfig {
+ public AnalyzerConfigExt(EnumSet<Language> languages, List<Path> sources, List<Path> classes) {
+ super(languages, sources, classes);
+ }
+ }
+
+ private static class MavenExt extends Maven {
+
+ private final File projDir;
+
+ public MavenExt(File projDir, Language ... languages) {
+ super(null, languages);
+ this.projDir = projDir;
+ }
+
+ @Override
+ public AnalyzerConfig main(String... packages) {
+ return new AnalyzerConfigExt(getLanguages(),
+ path(packages, canonicalPath("src/main/$language/")),
+ path(packages, canonicalPath("target/classes/")));
+ }
+
+ private String canonicalPath(String relPath) {
+ return _Files.canonicalPath(new File(projDir, relPath))
+ .orElse(relPath);
+ }
+
+ }
+
+}
diff --git a/tooling/javamodel/src/test/java/org/apache/isis/tooling/javamodel/test/AnalyzerTest.java b/tooling/javamodel/src/test/java/org/apache/isis/tooling/javamodel/test/AnalyzerTest.java
new file mode 100644
index 0000000..4b61fc7
--- /dev/null
+++ b/tooling/javamodel/src/test/java/org/apache/isis/tooling/javamodel/test/AnalyzerTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.isis.tooling.javamodel.test;
+
+import static guru.nidi.codeassert.config.Language.JAVA;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import org.apache.isis.tooling._infra._Files;
+import org.apache.isis.tooling.javamodel.AnalyzerConfigFactory;
+
+import guru.nidi.codeassert.config.Language;
+import lombok.val;
+
+class AnalyzerTest {
+
+ File projDir;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ File projRootFolder = new File("./").getAbsoluteFile().getParentFile().getParentFile().getParentFile();
+ projDir = new File(projRootFolder, "core/runtime");
+ System.out.println("running AnalyzerTest at " + projDir.getAbsolutePath());
+ }
+
+ @AfterEach
+ void tearDown() throws Exception {
+ }
+
+ @Test
+ void testSourceFileListing() {
+
+ val analyzerConfig = AnalyzerConfigFactory.maven(projDir, Language.JAVA).main();
+
+ val commonPath = projDir.getAbsolutePath();
+
+ Set<String> sources = analyzerConfig.getSources(JAVA)
+ .stream()
+ .map(File::getAbsolutePath)
+ .map(sourceFile->_Files.toRelativePath(commonPath, sourceFile))
+ .map(s->s.replace("\\", "/"))
+ .map(s->s.replace("/src/main/java/org/apache/isis/", "o.a.i/"))
+ .peek(System.out::println)
+ .collect(Collectors.toSet());
+
+ assertHasSomeSourceFiles(sources);
+ }
+
+ private void assertHasSomeSourceFiles(Set<String> sources) {
+ assertTrue(sources.contains("o.a.i/core/runtime/context/IsisAppCommonContext.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/context/IsisContext.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/context/memento/ObjectMemento.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/context/memento/ObjectMementoCollection.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/context/memento/ObjectMementoForEmpty.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/context/memento/ObjectMementoService.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/context/RuntimeContext.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/context/RuntimeContextBase.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/events/app/AppLifecycleEvent.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/events/iactn/IsisInteractionLifecycleEvent.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/events/persistence/PostStoreEvent.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/events/persistence/PreStoreEvent.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/events/persistence/TimestampService.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/events/RuntimeEventService.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/iactn/IsisInteraction.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/iactn/IsisInteractionFactory.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/iactn/IsisInteractionTracker.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/iactn/scope/IsisInteractionScope.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/iactn/scope/IsisInteractionScopeBeanFactoryPostProcessor.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/iactn/scope/IsisInteractionScopeCloseListener.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/iactn/template/AbstractIsisInteractionTemplate.java"));
+ assertTrue(sources.contains("o.a.i/core/runtime/IsisModuleCoreRuntime.java"));
+
+ }
+
+}
diff --git a/tooling/pom.xml b/tooling/pom.xml
index 4f9fe0c..61fbbbb 100644
--- a/tooling/pom.xml
+++ b/tooling/pom.xml
@@ -207,8 +207,9 @@
<modules>
<module>commons</module>
+ <module>javamodel</module>
<module>model4adoc</module>
- <module>project-model</module>
+ <module>projectmodel</module>
</modules>
<profiles>