parseInterfaceQName.
+ * + * @param _s a {@link java.lang.String} object. + * @return a {@link org.eclipse.steady.java.JavaInterfaceId} object. + */ + public static JavaInterfaceId parseInterfaceQName(@NotNull String _s) { + if (_s == null || _s.equals("")) throw new IllegalArgumentException("String null or empty"); + + final int i = _s.lastIndexOf('.'); + String class_name = null; + JavaPackageId pid = null; + JavaInterfaceId cid = null; + + // Create Java package id + if (i != -1) { + pid = new JavaPackageId(_s.substring(0, i)); + class_name = _s.substring(i + 1); + } else { + pid = JavaPackageId.DEFAULT_PACKAGE; + class_name = _s.substring(i + 1); + } + + // Create Java interface id (for regular or nested class) + int j = 0, k = 0; + do { + // HP, 12.09.2015: $ is also permitted in class names, i.e., it can also exist w/o a class + // context + j = class_name.indexOf("$", k); + if (j != -1) { + if (cid == null) cid = new JavaInterfaceId(pid, class_name.substring(k, j)); + else cid = new JavaInterfaceId(cid, class_name.substring(k, j)); + k = j + 1; + } else { + if (cid == null) cid = new JavaInterfaceId(pid, class_name.substring(k)); + else cid = new JavaInterfaceId(cid, class_name.substring(k)); + k = j + 1; + } + } while (j != -1); + // if(j!=-1) + // cid = new JavaClassId(new JavaClassId(pid, class_name.substring(0, j)), + // class_name.substring(j+1)); + // else + // cid = new JavaClassId(pid, class_name); + return cid; + } + /** * Creates a {@link JavaMethodId} from the given string, whereby the definition context is defaulted to * type {@link JavaId.Type#CLASS}. @@ -474,9 +525,11 @@ public static JavaMethodId parseMethodQName(JavaId.Type _ctx_type, String _s) { if (_s == null || _s.equals("")) throw new IllegalArgumentException("String null or empty"); if (_ctx_type == null - || (!_ctx_type.equals(JavaId.Type.CLASS) && !_ctx_type.equals(JavaId.Type.ENUM))) + || (!_ctx_type.equals(JavaId.Type.CLASS) + && !_ctx_type.equals(JavaId.Type.ENUM) + && !_ctx_type.equals(JavaId.Type.INTERFACE))) throw new IllegalArgumentException( - "Accepts context types CLASS or ENUM, got [" + _ctx_type + "]"); + "Accepts context types CLASS, ENUM and INTERFACE, got [" + _ctx_type + "]"); final int i = _s.indexOf('('); if (i == -1 || !_s.endsWith(")")) @@ -491,9 +544,13 @@ public static JavaMethodId parseMethodQName(JavaId.Type _ctx_type, String _s) { JavaId def_ctx = null; JavaMethodId mid = null; try { - if (_ctx_type.equals(JavaId.Type.CLASS)) def_ctx = JavaId.parseClassQName(_s.substring(0, j)); - else if (_ctx_type.equals(JavaId.Type.ENUM)) + if (_ctx_type.equals(JavaId.Type.CLASS)) { + def_ctx = JavaId.parseClassQName(_s.substring(0, j)); + } else if (_ctx_type.equals(JavaId.Type.ENUM)) { def_ctx = JavaId.parseEnumQName(_s.substring(0, j)); + } else if (_ctx_type.equals(JavaId.Type.INTERFACE)) { + def_ctx = JavaId.parseInterfaceQName(_s.substring(0, j)); + } mid = new JavaMethodId( @@ -501,7 +558,7 @@ else if (_ctx_type.equals(JavaId.Type.ENUM)) _s.substring(j + 1, i), JavaId.parseParameterTypes(_s.substring(i + 1, _s.length() - 1))); } catch (StringIndexOutOfBoundsException e) { - JavaId.log.error("Exception while parsing the string '" + _s + "'"); + JavaId.log.error("Exception while parsing the string [" + _s + "]"); } return mid; } @@ -534,9 +591,11 @@ public static JavaConstructorId parseConstructorQName( if (_s == null || _s.equals("")) throw new IllegalArgumentException("String null or empty"); if (_ctx_type == null - || (!_ctx_type.equals(JavaId.Type.CLASS) && !_ctx_type.equals(JavaId.Type.ENUM))) + || (!_ctx_type.equals(JavaId.Type.CLASS) + && !_ctx_type.equals(JavaId.Type.ENUM) + && !_ctx_type.equals(JavaId.Type.INTERFACE))) throw new IllegalArgumentException( - "Accepts context types CLASS or ENUM, got [" + _ctx_type + "]"); + "Accepts context types CLASS, ENUM and INTERFACE, got [" + _ctx_type + "]"); final int i = _s.indexOf('('); if (i == -1 || !_s.endsWith(")")) @@ -568,7 +627,7 @@ else if (_ctx_type.equals(JavaId.Type.ENUM)) } coid = new JavaConstructorId(def_ctx, params); } catch (StringIndexOutOfBoundsException e) { - JavaId.log.error("Exception while parsing the string '" + _s + "'"); + JavaId.log.error("Exception while parsing the string [" + _s + "]"); } return coid; } @@ -585,7 +644,7 @@ public static JavaClassInit parseClassInitQName(String _s) { final int i = _s.indexOf(JavaClassInit.NAME); if (i == -1) throw new IllegalArgumentException( - "String does not contain brackets " + "String does not contain " + JavaClassInit.NAME + ", as required for qualified names for Java class initializers"); @@ -594,7 +653,7 @@ public static JavaClassInit parseClassInitQName(String _s) { final JavaClassId cid = JavaId.parseClassQName(_s.substring(0, i - 1)); clinit = cid.getClassInit(); } catch (StringIndexOutOfBoundsException e) { - JavaId.log.error("Exception while parsing the string '" + _s + "'"); + JavaId.log.error("Exception while parsing the string [" + _s + "]"); } return clinit; } diff --git a/lang-java/src/main/java/org/eclipse/steady/java/monitor/ClassVisitor.java b/lang-java/src/main/java/org/eclipse/steady/java/monitor/ClassVisitor.java index 4ee9aad53..d381a0c58 100644 --- a/lang-java/src/main/java/org/eclipse/steady/java/monitor/ClassVisitor.java +++ b/lang-java/src/main/java/org/eclipse/steady/java/monitor/ClassVisitor.java @@ -110,10 +110,13 @@ private static final Logger getLog() { */ public ClassVisitor(CtClass _c) { // Build the JavaId - if (_c.isInterface()) - throw new IllegalArgumentException("[" + _c.getName() + "]: Interfaces are not supported"); - else if (_c.isEnum()) this.javaId = JavaId.parseEnumQName(_c.getName()); - else this.javaId = JavaId.parseClassQName(_c.getName()); + if (_c.isInterface()) { + this.javaId = JavaId.parseInterfaceQName(_c.getName()); + } else if (_c.isEnum()) { + this.javaId = JavaId.parseEnumQName(_c.getName()); + } else { + this.javaId = JavaId.parseClassQName(_c.getName()); + } this.qname = this.javaId.getQualifiedName(); this.c = _c; diff --git a/lang-java/src/main/java/org/eclipse/steady/java/tasks/JavaDebloatTask.java b/lang-java/src/main/java/org/eclipse/steady/java/tasks/JavaDebloatTask.java new file mode 100644 index 000000000..3bd964189 --- /dev/null +++ b/lang-java/src/main/java/org/eclipse/steady/java/tasks/JavaDebloatTask.java @@ -0,0 +1,335 @@ +/** + * This file is part of Eclipse Steady. + * + * Licensed 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. + * + * SPDX-License-Identifier: Apache-2.0 + * SPDX-FileCopyrightText: Copyright (c) 2018-2020 SAP SE or an SAP affiliate company and Eclipse Steady contributors + */ +package org.eclipse.steady.java.tasks; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.logging.log4j.Logger; +import org.eclipse.steady.core.util.CoreConfiguration; +import org.eclipse.steady.goals.GoalExecutionException; +import org.eclipse.steady.java.JavaId; +import org.eclipse.steady.shared.enums.ConstructType; +import org.eclipse.steady.shared.enums.GoalClient; +import org.eclipse.steady.shared.enums.ProgrammingLanguage; +import org.eclipse.steady.shared.json.model.ConstructId; +import org.eclipse.steady.shared.json.model.Dependency; +import org.eclipse.steady.shared.util.FileUtil; +import org.eclipse.steady.shared.util.StringUtil; +import org.eclipse.steady.tasks.AbstractTask; +import org.eclipse.steady.tasks.DebloatTask; +import org.vafer.jdependency.Clazz; +import org.vafer.jdependency.Clazzpath; +import org.vafer.jdependency.ClazzpathUnit; + +/** + *JavaBomTask class.
+ */ +public class JavaDebloatTask extends AbstractTask implements DebloatTask { + + private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(); + + private static final String[] EXT_FILTER = new String[] {"jar", "war", "class", "java", "aar"}; + + private SetAPP_DIRS="vulas.core.app.sourceDir"
*/
public static final String APP_DIRS = "vulas.core.app.sourceDir";
+ /** Constant TEST_DIRS="vulas.core.app.testDir"
*/
+ public static final String TEST_DIRS = "vulas.core.app.testDir";
/** Constant APP_PREFIXES="vulas.core.app.appPrefixes"
*/
public static final String APP_PREFIXES = "vulas.core.app.appPrefixes";
/** Constant APP_JAR_NAMES="vulas.core.app.appJarNames"
*/
@@ -125,6 +127,9 @@ public enum ConnectType {
/** Constant REP_LIB_ASSESS="vulas.report.createLibraryAssessments"
*/
public static final String REP_CREATE_AFF_LIB = "vulas.report.createLibraryAssessments";
+ /** Constant SLICING_DIR="vulas.slicing.slicingDir"
*/
+ public static final String SLICING_DIR = "vulas.slicing.slicingDir";
+
/** Constant SEQ_DEFAULT="vulas.core.sequence.defaultGoals"
*/
public static final String SEQ_DEFAULT = "vulas.core.sequence.defaultGoals";
diff --git a/lang/src/main/java/org/eclipse/steady/goals/DebloatGoal.java b/lang/src/main/java/org/eclipse/steady/goals/DebloatGoal.java
new file mode 100644
index 000000000..be03b87b0
--- /dev/null
+++ b/lang/src/main/java/org/eclipse/steady/goals/DebloatGoal.java
@@ -0,0 +1,138 @@
+/**
+ * This file is part of Eclipse Steady.
+ *
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * SPDX-FileCopyrightText: Copyright (c) 2018-2020 SAP SE or an SAP affiliate company and Eclipse Steady contributors
+ */
+package org.eclipse.steady.goals;
+
+import java.util.ServiceLoader;
+
+import org.apache.logging.log4j.Logger;
+import org.eclipse.steady.backend.BackendConnector;
+import org.eclipse.steady.shared.enums.GoalType;
+import org.eclipse.steady.shared.json.model.Application;
+import org.eclipse.steady.tasks.DebloatTask;
+
+/**
+ * NeededGoal class.
+ */ +public class DebloatGoal extends AbstractAppGoal { + + private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(); + + /** + *Constructor for DebloatGoal.
+ */ + public DebloatGoal() { + super(GoalType.DEBLOAT); + } + + // /** + // * {@inheritDoc} + // * + // * Evaluates the configuration setting {@link CoreConfiguration#APP_PREFIXES}. + // */ + // @Override + // protected void prepareExecution() throws GoalConfigurationException { + // super.prepareExecution(); + // } + + /** {@inheritDoc} */ + @Override + protected void executeTasks() throws Exception { + + // The application to be completed + Application a = this.getApplicationContext(); + + // Create, configure and execute tasks + final ServiceLoader