Isis-fish-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
April 2013
- 1 participants
- 1 discussions
r3822 - in branches/4.0.1: . src/main/java/fr/ifremer/isisfish src/main/java/fr/ifremer/isisfish/aspect src/main/java/fr/ifremer/isisfish/simulator/launcher src/main/java/fr/ifremer/isisfish/util src/main/resources
by echatellier@users.forge.codelutin.com 08 Apr '13
by echatellier@users.forge.codelutin.com 08 Apr '13
08 Apr '13
Author: echatellier
Date: 2013-04-08 16:55:26 +0200 (Mon, 08 Apr 2013)
New Revision: 3822
Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/3822
Log:
fixes #2255 : Move from aspectwerkz to aspectj
Added:
branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectJUrlClassLoader.java
branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectJWeavingAdaptor.java
Removed:
branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectClassLoader.java
Modified:
branches/4.0.1/pom.xml
branches/4.0.1/src/main/java/fr/ifremer/isisfish/IsisFish.java
branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/CacheAspect.java
branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/RuleAspect.java
branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java
branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/package-info.java
branches/4.0.1/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/Cache.java
branches/4.0.1/src/main/resources/log4j.properties
Modified: branches/4.0.1/pom.xml
===================================================================
--- branches/4.0.1/pom.xml 2013-03-11 17:04:52 UTC (rev 3821)
+++ branches/4.0.1/pom.xml 2013-04-08 14:55:26 UTC (rev 3822)
@@ -6,7 +6,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>3.4.8</version>
+ <version>3.4.9</version>
</parent>
<groupId>fr.ifremer</groupId>
@@ -182,14 +182,14 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
- <version>3.1.1</version>
+ <version>3.2</version>
<scope>runtime</scope> <!--script -->
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
- <version>1.3</version>
+ <version>1.3.1</version>
</dependency>
<dependency>
@@ -207,14 +207,14 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
- <version>1.7.2</version>
+ <version>1.7.5</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
- <version>1.7.2</version>
+ <version>1.7.5</version>
<scope>runtime</scope>
</dependency>
@@ -288,7 +288,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
- <version>1.3.170</version>
+ <version>1.3.171</version>
<scope>compile</scope>
</dependency>
@@ -300,24 +300,20 @@
<scope>runtime</scope>
</dependency>
- <!-- aspectwerkz -->
<dependency>
- <groupId>aspectwerkz</groupId>
- <artifactId>aspectwerkz</artifactId>
- <version>${aspectwerkzVersion}</version>
- <scope>compile</scope>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>1.7.2</version>
</dependency>
<dependency>
- <groupId>aspectwerkz</groupId>
- <artifactId>aspectwerkz-jdk5</artifactId>
- <version>${aspectwerkzVersion}</version>
- <scope>compile</scope>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <version>1.7.2</version>
</dependency>
<dependency>
- <groupId>aspectwerkz</groupId>
- <artifactId>aspectwerkz-core</artifactId>
- <version>${aspectwerkzVersion}</version>
- <scope>compile</scope>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjtools</artifactId>
+ <version>1.7.2</version>
</dependency>
<!-- ssj pour les calculs stockastiques -->
@@ -484,17 +480,15 @@
<license.organizationName>Ifremer, Codelutin</license.organizationName>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
- <animal.sniffer.skip>true</animal.sniffer.skip>
<!-- Dependencies version -->
- <jaxxVersion>2.5.12</jaxxVersion>
- <eugeneVersion>2.6.1</eugeneVersion>
- <topiaVersion>2.7.1</topiaVersion>
- <hibernateVersion>3.6.10.Final</hibernateVersion>
- <nuitonUtilsVersion>2.6.10</nuitonUtilsVersion>
+ <jaxxVersion>2.5.16</jaxxVersion>
+ <eugeneVersion>2.6.2</eugeneVersion>
+ <topiaVersion>2.8-SNAPSHOT</topiaVersion>
+ <hibernateVersion>4.2.0.Final</hibernateVersion>
+ <nuitonUtilsVersion>2.6.12</nuitonUtilsVersion>
<nuitonI18nVersion>2.5</nuitonI18nVersion>
<nuitonWidgetsVersion>1.1.1</nuitonWidgetsVersion>
- <aspectwerkzVersion>2.0</aspectwerkzVersion>
<redmine.releaseFiles>target/isis-fish-${project.version}-bin.zip</redmine.releaseFiles>
Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/IsisFish.java
===================================================================
--- branches/4.0.1/src/main/java/fr/ifremer/isisfish/IsisFish.java 2013-03-11 17:04:52 UTC (rev 3821)
+++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/IsisFish.java 2013-04-08 14:55:26 UTC (rev 3822)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2005 - 2012 Ifremer, CodeLutin, Chatellier Eric
+ * Copyright (C) 2005 - 2013 Ifremer, CodeLutin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -642,7 +642,7 @@
// using non recompiled script due to dependency changes
// this is the better solution found :
// remove isis build directory
- FileUtils.deleteQuietly(IsisFish.config.getCompileDirectory());
+ //FileUtils.deleteQuietly(IsisFish.config.getCompileDirectory());
ErrorHelper.showErrorDialog(null, _("isisfish.error.linkageerror.message"), cause);
}
Deleted: branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectClassLoader.java
===================================================================
--- branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectClassLoader.java 2013-03-11 17:04:52 UTC (rev 3821)
+++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectClassLoader.java 2013-04-08 14:55:26 UTC (rev 3822)
@@ -1,164 +0,0 @@
-/*
- * #%L
- * IsisFish
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 1999 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package fr.ifremer.isisfish.aspect;
-
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.codehaus.aspectwerkz.annotation.AspectAnnotationParser;
-import org.codehaus.aspectwerkz.definition.AdviceDefinition;
-import org.codehaus.aspectwerkz.definition.AspectDefinition;
-import org.codehaus.aspectwerkz.definition.DeploymentScope;
-import org.codehaus.aspectwerkz.definition.SystemDefinition;
-import org.codehaus.aspectwerkz.definition.SystemDefinitionContainer;
-import org.codehaus.aspectwerkz.expression.ExpressionInfo;
-import org.codehaus.aspectwerkz.hook.impl.ClassPreProcessorHelper;
-import org.codehaus.aspectwerkz.reflect.ClassInfo;
-import org.codehaus.aspectwerkz.reflect.impl.asm.AsmClassInfo;
-import org.codehaus.aspectwerkz.reflect.impl.java.JavaClassInfo;
-import org.codehaus.aspectwerkz.transform.inlining.AspectModelManager;
-
-import sun.misc.Resource;
-import sun.misc.URLClassPath;
-
-/**
- * Aspectwerkz class loader.
- *
- * http://aspectwerkz.codehaus.org/xref/org/codehaus/aspectwerkz/transform/inl…
- *
- * Created: 30 mars 07 00:31:22
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-public class AspectClassLoader extends URLClassLoader {
-
- /**
- * Class loader constructor.
- *
- * @param urls parent urlclassloader url
- * @param parent parent class loader
- */
- public AspectClassLoader(URL[] urls, ClassLoader parent) {
- super(urls, parent);
- ClassPreProcessorHelper.initializePreProcessor();
- }
-
- @Override
- protected Class<?> findClass(String name) throws ClassNotFoundException {
- String path = name.replace('.', '/').concat(".class");
- URLClassPath ucp = new URLClassPath(getURLs());
- Resource res = ucp.getResource(path, false);
- if (res != null) {
- //definePackage(name.substring(0, name.lastIndexOf(".")), null, null);
- try {
- byte[] b = res.getBytes();
- byte[] transformed = ClassPreProcessorHelper.defineClass0Pre(this, name, b, 0, b.length, null);
- return defineClass(name, transformed, 0, transformed.length);
- } catch (IOException e) {
- throw new ClassNotFoundException("Can't build aspect for class", e);
- }
- } else {
- throw new ClassNotFoundException(name);
- }
- }
-
- /**
- * Register new aspect.
- *
- * @param aspectClass aspect class to register
- */
- public void deploy(Class<?> aspectClass) {
- String className = aspectClass.getName();
- try {
- aspectClass = Class.forName(className, false, this);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("could not load class [" + className + "] in class loader [" + this + "]");
- }
-
- final ClassInfo aspectClassInfo = JavaClassInfo.getClassInfo(aspectClass);
-
- // create a new aspect def and fill it up with the annotation def from the aspect class
- final SystemDefinition systemDef = SystemDefinitionContainer.getVirtualDefinitionAt(this);
- final AspectDefinition newAspectDef = new AspectDefinition(className, aspectClassInfo, systemDef);
- getNewExpressionsForAspect(aspectClass, newAspectDef, systemDef, DeploymentScope.MATCH_ALL);
- }
-
- /**
- * Returns a set with the new expressions for the advice in the aspect to deploy.
- *
- * @param aspectClass
- * @param newAspectDef
- * @param newAspectDef
- * @param systemDef
- * @param deploymentScope
- * @return a set with the new expressions
- */
- private Set getNewExpressionsForAspect(final Class aspectClass,
- final AspectDefinition newAspectDef,
- final SystemDefinition systemDef,
- final DeploymentScope deploymentScope) {
- final ClassLoader aspectLoader = aspectClass.getClassLoader();
- final String aspectName = aspectClass.getName();
-
- final ClassInfo classInfo = AsmClassInfo.getClassInfo(aspectName, aspectLoader);
-
- AspectModelManager.defineAspect(classInfo, newAspectDef, aspectLoader);
-
- AspectAnnotationParser.parse(classInfo, newAspectDef, aspectLoader);
-
- AspectDefinition aspectDef = systemDef.getAspectDefinition(aspectName);
- if (aspectDef != null) {
- // if in def already reuse some of the settings that can have been overridded by XML def
- newAspectDef.setContainerClassName(aspectDef.getContainerClassName());
- newAspectDef.setDeploymentModel(aspectDef.getDeploymentModel());
- }
-
- systemDef.addAspectOverwriteIfExists(newAspectDef);
-
- final Set newExpressions = new HashSet();
- for (Iterator it2 = newAspectDef.getAdviceDefinitions().iterator(); it2.hasNext();) {
- AdviceDefinition adviceDef = (AdviceDefinition) it2.next();
- ExpressionInfo oldExpression = adviceDef.getExpressionInfo();
- if (oldExpression == null) {
- continue;
- }
- // deploymentHandle.registerDefinitionChange(adviceDef, oldExpression);
-
- final ExpressionInfo newExpression = deploymentScope.newExpressionInfo(oldExpression);
- adviceDef.setExpressionInfo(newExpression);
- newExpressions.add(newExpression);
- }
- return newExpressions;
- }
-}
Added: branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectJUrlClassLoader.java
===================================================================
--- branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectJUrlClassLoader.java (rev 0)
+++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectJUrlClassLoader.java 2013-04-08 14:55:26 UTC (rev 3822)
@@ -0,0 +1,156 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 Ifremer, Code Lutin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+package fr.ifremer.isisfish.aspect;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.CodeSource;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.aspectj.bridge.AbortException;
+import org.aspectj.weaver.bcel.ExtensibleURLClassLoader;
+import org.aspectj.weaver.tools.Trace;
+import org.aspectj.weaver.tools.TraceFactory;
+import org.aspectj.weaver.tools.WeavingClassLoader;
+
+public class AspectJUrlClassLoader extends ExtensibleURLClassLoader implements WeavingClassLoader {
+
+ public static final String WEAVING_CLASS_PATH = "aj.class.path";
+ public static final String WEAVING_ASPECT_PATH = "aj.aspect.path";
+
+ private URL[] aspectURLs;
+ private AspectJWeavingAdaptor adaptor;
+ private boolean initializingAdaptor;
+ private Map generatedClasses = new HashMap(); /* String -> byte[] */
+
+ private static Trace trace = TraceFactory.getTraceFactory().getTrace(AspectJUrlClassLoader.class);
+
+ public AspectJUrlClassLoader(URL[] urls, ClassLoader parent) {
+ super(urls, parent);
+ if (trace.isTraceEnabled())
+ trace.enter("<init>", this, new Object[] { urls, parent });
+ if (trace.isTraceEnabled())
+ trace.exit("<init>");
+
+ adaptor = new AspectJWeavingAdaptor(getParent(), this);
+ }
+
+ private static String getAspectPath() {
+ return System.getProperty(WEAVING_ASPECT_PATH, "");
+ }
+
+ private static String getClassPath() {
+ return System.getProperty(WEAVING_CLASS_PATH, "");
+ }
+
+ protected void addURL(URL url) {
+ adaptor.addURL(url);
+ super.addURL(url);
+ }
+
+ /**
+ * Override to weave class using WeavingAdaptor
+ */
+ protected Class defineClass(String name, byte[] b, CodeSource cs) throws IOException {
+ if (trace.isTraceEnabled())
+ trace.enter("defineClass", this, new Object[] { name, b, cs });
+ // System.err.println("? WeavingURLClassLoader.defineClass(" + name + ", [" + b.length + "])");
+ byte orig[] = b;
+ /* Avoid recursion during adaptor initialization */
+ if (!initializingAdaptor) {
+
+ /* Need to defer creation because of possible recursion during constructor execution */
+ if (adaptor == null && !initializingAdaptor) {
+ //createAdaptor();
+ }
+
+ try {
+ b = adaptor.weaveClass(name, b, false);
+ } catch (AbortException ex) {
+ trace.error("defineClass", ex);
+ throw ex;
+ } catch (Throwable th) {
+ trace.error("defineClass", th);
+ }
+ }
+ Class clazz;
+
+ // On error, define the original form of the class and log the issue
+ try {
+ clazz= super.defineClass(name, b, cs);
+ } catch (Throwable th) {
+ trace.error("Weaving class problem. Original class has been returned. The error was caused because of: " + th, th);
+ clazz= super.defineClass(name, orig, cs);
+ }
+ if (trace.isTraceEnabled())
+ trace.exit("defineClass", clazz);
+ return clazz;
+ }
+
+ /**
+ * Override to find classes generated by WeavingAdaptor
+ */
+ protected byte[] getBytes(String name) throws IOException {
+ byte[] bytes = super.getBytes(name);
+
+ if (bytes == null) {
+ // return adaptor.findClass(name);
+ return (byte[]) generatedClasses.remove(name);
+ }
+
+ return bytes;
+ }
+
+ /**
+ * Implement method from WeavingClassLoader
+ */
+ public URL[] getAspectURLs() {
+ return aspectURLs;
+ }
+
+ public void acceptClass (String name, byte[] classBytes, byte[] weavedBytes) {
+ generatedClasses.put(name, weavedBytes);
+ }
+
+ public void deploy(Class<?> aspectClass) {
+ byte[] result = adaptor.deploy(aspectClass);
+ // this classloader need to be implemented in "local first" strategy
+ // and aspectized class must be forced into current classloader
+ // otherwize, aspectj will complain about missing 'aspectOf' methods
+ defineClass(aspectClass.getName(), result, 0, result.length);
+ }
+
+ /**
+ * Mark classloader as configured with aspects and tell to prepare for
+ * weaving.
+ *
+ * Must call this method to avoid NPE in aspectj weaver.
+ */
+ public void prepare() {
+ adaptor.prepare();
+ }
+}
Property changes on: branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectJUrlClassLoader.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectJWeavingAdaptor.java
===================================================================
--- branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectJWeavingAdaptor.java (rev 0)
+++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectJWeavingAdaptor.java 2013-04-08 14:55:26 UTC (rev 3822)
@@ -0,0 +1,237 @@
+/*
+ * #%L
+ * IsisFish
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2013 Ifremer, Code Lutin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+package fr.ifremer.isisfish.aspect;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.aspectj.apache.bcel.classfile.ClassParser;
+import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.bridge.IMessageHandler;
+import org.aspectj.util.FileUtil;
+import org.aspectj.util.LangUtil;
+import org.aspectj.weaver.CrosscuttingMembersSet;
+import org.aspectj.weaver.IClassFileProvider;
+import org.aspectj.weaver.IUnwovenClassFile;
+import org.aspectj.weaver.IWeaveRequestor;
+import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.bcel.BcelObjectType;
+import org.aspectj.weaver.bcel.BcelWeaver;
+import org.aspectj.weaver.bcel.BcelWorld;
+import org.aspectj.weaver.bcel.UnwovenClassFile;
+import org.aspectj.weaver.tools.WeavingAdaptor;
+import org.aspectj.weaver.tools.WeavingClassLoader;
+import org.aspectj.weaver.tools.cache.SimpleCache;
+import org.aspectj.weaver.tools.cache.SimpleCacheFactory;
+
+public class AspectJWeavingAdaptor extends WeavingAdaptor {
+
+ protected ClassLoader parentLoader;
+
+ protected CrosscuttingMembersSet xcutSet;
+
+ public AspectJWeavingAdaptor(ClassLoader parentLoader, WeavingClassLoader loader) {
+ this.parentLoader = parentLoader;
+
+ generatedClassHandler = loader;
+ init((ClassLoader)loader, getFullClassPath((ClassLoader) loader));
+ }
+
+ /**
+ * Initialize the WeavingAdapter
+ * @param loader ClassLoader used by this adapter; which can be null
+ * @param classPath classpath of this adapter
+ * @param aspectPath list of aspect paths
+ */
+ private void init(ClassLoader loader, List<String> classPath) {
+ try {
+ //XXX call to private code "abortOnError = true;"
+ Field abortOnErrorField = WeavingAdaptor.class.getDeclaredField("abortOnError");
+ abortOnErrorField.setAccessible(true);
+ abortOnErrorField.set(this, true);
+
+ createMessageHandler();
+
+ info("using classpath: " + classPath);
+ //info("using aspectpath: " + aspectPath);
+
+ Field messageHandlerField = WeavingAdaptor.class.getDeclaredField("messageHandler");
+ messageHandlerField.setAccessible(true);
+ IMessageHandler messageHandler = (IMessageHandler)messageHandlerField.get(this);
+ bcelWorld = new BcelWorld(classPath, messageHandler, null);
+ bcelWorld.setXnoInline(false);
+ bcelWorld.getLint().loadDefaultProperties();
+ if (LangUtil.is15VMOrGreater()) {
+ bcelWorld.setBehaveInJava5Way(true);
+ }
+
+ weaver = new BcelWeaver(bcelWorld);
+ //registerAspectLibraries(aspectPath);
+ //initializeCache(loader, aspectPath, null, getMessageHandler());
+
+ //XXX call to private code "enabled = true;"
+ Field enabledField = WeavingAdaptor.class.getDeclaredField("enabled");
+ enabledField.setAccessible(true);
+ enabledField.set(this, true);
+
+ // get private field instance
+ //XXX call to private code "xcutSet = weaver.xcutSet"
+ Field xcutSetField = BcelWeaver.class.getDeclaredField("xcutSet");
+ xcutSetField.setAccessible(true);
+ xcutSet = (CrosscuttingMembersSet) xcutSetField.get(weaver);
+
+ } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public byte[] deploy(Class<?> aspectClass) {
+ byte[] result = null;
+ try {
+ String name = aspectClass.getName();
+ InputStream is = AspectJWeavingAdaptor.class.getResourceAsStream("/" + name.replace('.', '/') + ".class");
+ byte[] bytes = FileUtil.readAsByteArray(is);
+ is.close();
+ ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), name);
+
+ JavaClass jc = parser.parse();
+ BcelObjectType bcType = bcelWorld.addSourceObjectType(jc, false);
+ ResolvedType type = bcType.getResolvedTypeX();
+ xcutSet.addOrReplaceAspect(type);
+
+ WeavingClassFileProvider2 wcp = new WeavingClassFileProvider2(name, bytes);
+ wcp.setApplyAtAspectJMungersOnly();
+ weaver.weave(wcp);
+ result = wcp.getBytes();
+
+ } catch (IOException e) {
+ throw new RuntimeException("Can't create aspect", e);
+ }
+
+ return result;
+ }
+
+ /**
+ * Mark bcel weaver ready for weaving classes.
+ */
+ public void prepare() {
+ weaver.prepareForWeave();
+ }
+
+ private class WeavingClassFileProvider2 implements IClassFileProvider {
+
+ private final UnwovenClassFile unwovenClass;
+ private final List<UnwovenClassFile> unwovenClasses = new ArrayList<UnwovenClassFile>();
+ private IUnwovenClassFile wovenClass;
+ private boolean isApplyAtAspectJMungersOnly = false;
+
+ public WeavingClassFileProvider2(String name, byte[] bytes) {
+ ensureDelegateInitialized(name, bytes);
+ this.unwovenClass = new UnwovenClassFile(name, name /*delegateForCurrentClass.getResolvedTypeX().getName()*/, bytes);
+ this.unwovenClasses.add(unwovenClass);
+
+ if (shouldDump(name.replace('/', '.'), true)) {
+ dump(name, bytes, true);
+ }
+
+ }
+
+ public void setApplyAtAspectJMungersOnly() {
+ isApplyAtAspectJMungersOnly = true;
+ }
+
+ public boolean isApplyAtAspectJMungersOnly() {
+ return isApplyAtAspectJMungersOnly;
+ }
+
+ public byte[] getBytes() {
+ if (wovenClass != null) {
+ return wovenClass.getBytes();
+ } else {
+ return unwovenClass.getBytes();
+ }
+ }
+
+ public Iterator<UnwovenClassFile> getClassFileIterator() {
+ return unwovenClasses.iterator();
+ }
+
+ public IWeaveRequestor getRequestor() {
+ return new IWeaveRequestor() {
+
+ public void acceptResult(IUnwovenClassFile result) {
+ if (wovenClass == null) {
+ wovenClass = result;
+ String name = result.getClassName();
+ if (shouldDump(name.replace('/', '.'), false)) {
+ dump(name, result.getBytes(), false);
+ }
+ } else {
+ // Classes generated by weaver e.g. around closure advice
+ String className = result.getClassName();
+ byte[] resultBytes = result.getBytes();
+
+ if (SimpleCacheFactory.isEnabled()) {
+ SimpleCache lacache=SimpleCacheFactory.createSimpleCache();
+ lacache.put(result.getClassName(), wovenClass.getBytes(), result.getBytes());
+ lacache.addGeneratedClassesNames(wovenClass.getClassName(), wovenClass.getBytes(), result.getClassName());
+ }
+
+ generatedClasses.put(className, result);
+ generatedClasses.put(wovenClass.getClassName(), result);
+ generatedClassHandler.acceptClass(className, null, resultBytes);
+ }
+ }
+
+ public void processingReweavableState() {
+ }
+
+ public void addingTypeMungers() {
+ }
+
+ public void weavingAspects() {
+ }
+
+ public void weavingClasses() {
+ }
+
+ public void weaveCompleted() {
+ // ResolvedType.resetPrimitives();
+ if (delegateForCurrentClass != null) {
+ delegateForCurrentClass.weavingCompleted();
+ }
+ // ResolvedType.resetPrimitives();
+ // bcelWorld.discardType(typeBeingProcessed.getResolvedTypeX()); // work in progress
+ }
+ };
+ }
+ }
+}
Property changes on: branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/AspectJWeavingAdaptor.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/CacheAspect.java
===================================================================
--- branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/CacheAspect.java 2013-03-11 17:04:52 UTC (rev 3821)
+++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/CacheAspect.java 2013-04-08 14:55:26 UTC (rev 3822)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2006 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin
+ * Copyright (C) 2006 - 2013 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -30,13 +30,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.codehaus.aspectwerkz.annotation.Around;
-import org.codehaus.aspectwerkz.annotation.Aspect;
-import org.codehaus.aspectwerkz.annotation.Expression;
-import org.codehaus.aspectwerkz.definition.Pointcut;
-import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
-import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
-import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.reflect.MethodSignature;
import fr.ifremer.isisfish.simulator.SimulationContext;
import fr.ifremer.isisfish.util.Cache;
@@ -52,14 +49,14 @@
* Last update: $Date$
* by : $Author$
*/
-@Aspect("perJVM")
+@Aspect
public class CacheAspect {
/** to use log facility, just put in your code: log.info(\"...\"); */
static private Log log = LogFactory.getLog(CacheAspect.class);
- @Expression("execution(* scripts..*(..))")
- Pointcut scriptsMethod;
+ //@Expression("execution(* scripts..*(..))")
+ //Pointcut scriptsMethod;
public CacheAspect() {
}
@@ -74,16 +71,16 @@
Cache result = context.getCache();
return result;
}
-
- @Around("scriptsMethod")
- public Object call(final JoinPoint jp) throws Throwable {
+
+ @Around("execution(* scripts..*(..))")
+ public Object call(final ProceedingJoinPoint jp) throws Throwable {
Method method = ((MethodSignature)jp.getSignature()).getMethod();
- Object[] args = ((MethodRtti)jp.getRtti()).getParameterValues();
+ Object[] args = jp.getArgs();
Object result = getCache().get(method, args, jp);
if (log.isTraceEnabled()) {
log.trace(((MethodSignature)jp.getSignature()).getMethod()
- + " args " + Arrays.toString(((MethodRtti)jp.getRtti()).getParameterValues())
+ + " args " + Arrays.toString(jp.getArgs())
+ " result = " + result);
}
return result;
Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/RuleAspect.java
===================================================================
--- branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/RuleAspect.java 2013-03-11 17:04:52 UTC (rev 3821)
+++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/RuleAspect.java 2013-04-08 14:55:26 UTC (rev 3822)
@@ -27,9 +27,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.codehaus.aspectwerkz.annotation.Around;
-import org.codehaus.aspectwerkz.annotation.Aspect;
-import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
import fr.ifremer.isisfish.datastore.SimulationInformation;
import fr.ifremer.isisfish.datastore.SimulationStorage;
@@ -50,7 +51,7 @@
* Last update : $Date$
* By : $Author$
*/
-@Aspect("perInstance")
+@Aspect
public class RuleAspect {
/**
@@ -71,7 +72,7 @@
* @throws Throwable
*/
@Around("execution(* rules.*.init(..))")
- public Object initCall(final JoinPoint jp) throws Throwable {
+ public Object initCall(final ProceedingJoinPoint jp) throws Throwable {
Object result = makeTimedCall(jp, State.INIT);
return result;
@@ -86,7 +87,7 @@
* @throws Throwable
*/
@Around("execution(* rules.*.preAction(..))")
- public Object initPreCall(final JoinPoint jp) throws Throwable {
+ public Object initPreCall(final ProceedingJoinPoint jp) throws Throwable {
Object result = makeTimedCall(jp, State.PRE);
return result;
@@ -100,7 +101,7 @@
* @throws Throwable
*/
@Around("execution(* rules.*.postAction(..))")
- public Object initPostCall(final JoinPoint jp) throws Throwable {
+ public Object initPostCall(final ProceedingJoinPoint jp) throws Throwable {
Object result = makeTimedCall(jp, State.POST);
return result;
@@ -113,10 +114,10 @@
* @param state state
* @throws Throwable
*/
- protected Object makeTimedCall(JoinPoint jp, State state) throws Throwable {
+ protected Object makeTimedCall(ProceedingJoinPoint jp, State state) throws Throwable {
if (log.isTraceEnabled()) {
- log.trace("Rule aspect called : " + jp.getCalleeClass().getSimpleName());
+ log.trace("Rule aspect called : " + jp.getTarget().getClass().getSimpleName());
}
// get time before
@@ -155,7 +156,7 @@
if (simulation != null) {
// get rule information
- Class<?> calleeClass = jp.getCalleeClass();
+ Class<?> calleeClass = jp.getTarget().getClass();
String ruleName = calleeClass.getSimpleName();
SimulationInformation info = simulation.getInformation();
Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java
===================================================================
--- branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java 2013-03-11 17:04:52 UTC (rev 3821)
+++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/TraceAspect.java 2013-04-08 14:55:26 UTC (rev 3822)
@@ -27,14 +27,12 @@
import java.lang.reflect.Method;
-import org.codehaus.aspectwerkz.annotation.After;
-import org.codehaus.aspectwerkz.annotation.AfterThrowing;
-import org.codehaus.aspectwerkz.annotation.Aspect;
-import org.codehaus.aspectwerkz.annotation.Before;
-import org.codehaus.aspectwerkz.annotation.Expression;
-import org.codehaus.aspectwerkz.definition.Pointcut;
-import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
-import org.codehaus.aspectwerkz.joinpoint.MethodSignature;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.AfterThrowing;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.reflect.MethodSignature;
import fr.ifremer.isisfish.simulator.SimulationContext;
import fr.ifremer.isisfish.util.Trace;
@@ -53,15 +51,15 @@
* Last update: $Date$
* by : $Author$
*/
-@Aspect("perJVM")
+@Aspect
public class TraceAspect {
- @Expression("execution(* scripts..*(..))"
+ /*@Pointcut("execution(* scripts..*(..))"
+ " || execution(* simulators..*(..))"
+ " || execution(* rules..*(..)) "
+ " || execution(* simulationplans..*(..)) "
+ " || execution(* formules..*(..))")
- Pointcut executeMethod;
+ Pointcut executeMethod;*/
public TraceAspect() {
}
@@ -77,18 +75,31 @@
return result;
}
- @Before("executeMethod")
+ @Before("execution(* scripts..*(..))"
+ + " || execution(* simulators..*(..))"
+ + " || execution(* rules..*(..)) "
+ + " || execution(* simulationplans..*(..)) "
+ + " || execution(* formules..*(..))")
public void traceBeforeExecute(JoinPoint jp) {
getTrace().traceBefore();
}
- @AfterThrowing(type = "java.lang.Exception", pointcut = "executeMethod")
- public void traceAfterThrowingExecute(JoinPoint jp) {
+ @AfterThrowing(throwing = "ex",
+ pointcut = "execution(* scripts..*(..))"
+ + " || execution(* simulators..*(..))"
+ + " || execution(* rules..*(..)) "
+ + " || execution(* simulationplans..*(..)) "
+ + " || execution(* formules..*(..))")
+ public void traceAfterThrowingExecute(JoinPoint jp, Exception ex) {
// si une exeption est leve, il faut faire la meme chose
traceAfterExecute(jp);
}
- @After("executeMethod")
+ @After("execution(* scripts..*(..))"
+ + " || execution(* simulators..*(..))"
+ + " || execution(* rules..*(..)) "
+ + " || execution(* simulationplans..*(..)) "
+ + " || execution(* formules..*(..))")
public void traceAfterExecute(JoinPoint jp) {
Method method = ((MethodSignature) jp.getSignature()).getMethod();
getTrace().traceAfterCall(method);
Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/package-info.java
===================================================================
--- branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/package-info.java 2013-03-11 17:04:52 UTC (rev 3821)
+++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/aspect/package-info.java 2013-04-08 14:55:26 UTC (rev 3822)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 1999 - 2010 Ifremer, CodeLutin
+ * Copyright (C) 1999 - 2013 Ifremer, CodeLutin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -27,8 +27,8 @@
*
* Contains two aspects :
* <ul>
- * <li>{@link fr.ifremer.isisfish.aspect.Cache} : cache aspect</li>
- * <li>{@link fr.ifremer.isisfish.aspect.Trace} : trace expect</li>
+ * <li>{@link fr.ifremer.isisfish.aspect.CacheAspect} : cache aspect</li>
+ * <li>{@link fr.ifremer.isisfish.aspect.TraceAspect} : trace expect</li>
* <li>{@link fr.ifremer.isisfish.aspect.RuleAspect} : rule timing aspect</li>
* </ul>
*/
Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java
===================================================================
--- branches/4.0.1/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2013-03-11 17:04:52 UTC (rev 3821)
+++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/simulator/launcher/InProcessSimulatorLauncher.java 2013-04-08 14:55:26 UTC (rev 3822)
@@ -37,6 +37,7 @@
import java.util.List;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.apache.commons.logging.Log;
@@ -52,7 +53,7 @@
import fr.ifremer.isisfish.IsisConfig;
import fr.ifremer.isisfish.IsisFish;
import fr.ifremer.isisfish.IsisFishRuntimeException;
-import fr.ifremer.isisfish.aspect.AspectClassLoader;
+import fr.ifremer.isisfish.aspect.AspectJUrlClassLoader;
import fr.ifremer.isisfish.aspect.CacheAspect;
import fr.ifremer.isisfish.aspect.RuleAspect;
import fr.ifremer.isisfish.aspect.TraceAspect;
@@ -276,17 +277,14 @@
* @param directory le répertoire qui servira pour le classloader
* @return le classe loader modifié
*/
- protected AspectClassLoader changeClassLoader(Thread thread, File directory) {
+ protected AspectJUrlClassLoader changeClassLoader(Thread thread, File directory) {
try {
URL[] classpath = new URL[] { directory.toURI().toURL(),
// poussin 20080821 : il semble ne plus trouve les formules,
// est-ce mieux avec le compile dir ?
IsisFish.config.getCompileDirectory().toURI().toURL() };
- //URL [] classpath = new URL[]{directory.toURL()};
- AspectClassLoader loader = new AspectClassLoader(classpath,
- IsisFish.class.getClassLoader()); //new URLClassLoader(classpath);
- //AspectClassLoader loader = new AspectClassLoader(classpath, ClassLoader.getSystemClassLoader());
- //new URLClassLoader(classpath);
+ AspectJUrlClassLoader loader = new AspectJUrlClassLoader(classpath,
+ IsisFish.class.getClassLoader());
thread.setContextClassLoader(loader);
log.info("Classloader used for simulation: " + loader + " "
+ Arrays.toString(loader.getURLs()));
@@ -318,7 +316,7 @@
+ IsisConfig.getVersion());
long start = System.nanoTime();
simulation.getInformation().setSimulationStart(new java.util.Date());
- AspectClassLoader classLoader;
+ AspectJUrlClassLoader classLoader = null;
try {
File rootDirectory = simulation.getDirectory();
@@ -364,6 +362,8 @@
}
}
+ classLoader.prepare();
+
// recherche du simulateur a utiliser
String simulatorName = parameters.getSimulatorName();
SimulatorStorage simulator = SimulatorStorage
@@ -474,6 +474,12 @@
simulation.getInformation().setOptimizationUsage(cache);
}
+ // try to fix memory leak
+ LogFactory.release(classLoader);
+
+ // close classloader to release resource
+ IOUtils.closeQuietly(classLoader);
+
// cleanup specific context build directory
File simulationBuildDirectory = IsisFish.config.getCompileDirectory();
if (log.isDebugEnabled()) {
Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/Cache.java
===================================================================
--- branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/Cache.java 2013-03-11 17:04:52 UTC (rev 3821)
+++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/Cache.java 2013-04-08 14:55:26 UTC (rev 3822)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2006 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin
+ * Copyright (C) 2006 - 2013 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -29,7 +29,7 @@
import java.util.Map;
import org.apache.commons.collections.map.ReferenceMap;
-import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
import org.nuiton.topia.persistence.TopiaEntity;
import fr.ifremer.isisfish.simulator.SimulationContext;
@@ -196,8 +196,8 @@
*/
protected Object realCall(Object defaultValue) throws Throwable {
Object result = defaultValue;
- if (defaultValue instanceof JoinPoint) {
- result = ((JoinPoint)defaultValue).proceed();
+ if (defaultValue instanceof ProceedingJoinPoint) {
+ result = ((ProceedingJoinPoint)defaultValue).proceed();
}
return result;
}
Modified: branches/4.0.1/src/main/resources/log4j.properties
===================================================================
--- branches/4.0.1/src/main/resources/log4j.properties 2013-03-11 17:04:52 UTC (rev 3821)
+++ branches/4.0.1/src/main/resources/log4j.properties 2013-04-08 14:55:26 UTC (rev 3822)
@@ -5,7 +5,7 @@
# $Id$
# $HeadURL$
# %%
-# Copyright (C) 2005 - 2011 Ifremer, CodeLutin, Chatellier Eric
+# Copyright (C) 2005 - 2013 Ifremer, CodeLutin, Chatellier Eric
# %%
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
1
0