瀏覽代碼

#366 : remove static EFSFileSystemAccess#getProject

Johannes Dicks 9 年之前
父節點
當前提交
a90934d22d

+ 2 - 38
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/filesystem/EFSResourceFileSystemAccess.java

@@ -17,7 +17,6 @@ import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
 import org.eclipse.emf.common.util.URI;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2;
@@ -25,60 +24,25 @@ import org.eclipse.xtext.generator.IFileSystemAccess;
 import org.eclipse.xtext.generator.OutputConfiguration;
 import org.eclipse.xtext.util.StringInputStream;
 import org.yakindu.sct.generator.core.features.ICoreFeatureConstants;
-import org.yakindu.sct.generator.core.library.OutletFeatureHelperImpl;
 import org.yakindu.sct.generator.core.util.ClasspathChanger;
-import org.yakindu.sct.model.sgen.GeneratorEntry;
 
 public class EFSResourceFileSystemAccess extends EclipseResourceFileSystemAccess2 implements SCTFileSystemAccess {
 
-	/**
-	 * Returns an IProject for the configured target project. The
-	 * {@link IProject} is returned even if the project does not exist yet.
-	 * 
-	 * @param entry
-	 * @return
-	 */
-	public static IProject getTargetProject(GeneratorEntry entry) {
-		String stringValue = new OutletFeatureHelperImpl().getTargetProjectValue(entry).getStringValue();
-		if (Platform.isRunning()) {
-
-			IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(stringValue);
-
-			return project;
-		} else
-			throw new IllegalStateException("The " + EFSResourceFileSystemAccess.class.getSimpleName()
-					+ " needs a running " + Platform.class.getName());
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.eclipse.xtext.generator.AbstractFileSystemAccess#setOutputPath(java.
-	 * lang.String, java.lang.String)
-	 */
 	@Override
 	public void setOutputPath(String outputName, String path) {
 		super.setOutputPath(outputName, path);
 		// FIXME !!! ??? setting the targetProject has to be done firstly
 		trySetTargetProject(outputName, path);
 		// otherwise java classpath extension will fail, MSG?
-//		if (isOutputFolder(outputName)) {
 			IProject project = getProject();
 			if (isValidProject(project)) {
-				// FIXME !!! classpathchanger!?
+				// FIXME !!! should be handled if and only of java/xtend is generated?!
 				if (hasJavaNature(project) && hasClasspath(project)) {
 					new ClasspathChanger().addFolderToClassPath(project, path);
 				}
 			}
-//		}
 	}
-//FIXME !!! ???
-//	protected boolean isOutputFolder(String outputName) {
-//		return outputName.equals(IFileSystemAccess.DEFAULT_OUTPUT)
-//				|| outputName.equals(ICoreFeatureConstants.OUTLET_FEATURE_LIBRARY_TARGET_FOLDER)
-//				|| outputName.equals(ICoreFeatureConstants.OUTLET_FEATURE_TARGET_FOLDER);
-//	}
+
 
 	protected void trySetTargetProject(String outputName, String path) {
 		if (outputName.equals(ICoreFeatureConstants.OUTLET_FEATURE_TARGET_PROJECT)) {

+ 3 - 16
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractXpandBasedCodeGenerator.java

@@ -13,10 +13,6 @@ package org.yakindu.sct.generator.core.impl;
 import java.util.Collections;
 import java.util.Set;
 
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.emf.ecore.EPackage;
 import org.eclipse.emf.ecore.EcorePackage;
 import org.eclipse.xpand2.XpandExecutionContext;
@@ -33,7 +29,6 @@ import org.eclipse.xtext.generator.IFileSystemAccess;
 import org.yakindu.base.base.BasePackage;
 import org.yakindu.base.types.TypesPackage;
 import org.yakindu.sct.generator.core.features.ICoreFeatureConstants;
-import org.yakindu.sct.generator.core.filesystem.EFSResourceFileSystemAccess;
 import org.yakindu.sct.model.sexec.ExecutionFlow;
 import org.yakindu.sct.model.sexec.SexecPackage;
 import org.yakindu.sct.model.sgen.GeneratorEntry;
@@ -59,6 +54,8 @@ public abstract class AbstractXpandBasedCodeGenerator extends AbstractSExecModel
 
 	public static final String LIBRARY_TARGET_FOLDER_OUTLET = "LIBRARY_TARGET_FOLDER";
 
+	private EFSHelper efsHelper = new EFSHelper();
+
 	public abstract String getTemplatePath();
 
 	/**
@@ -98,7 +95,7 @@ public abstract class AbstractXpandBasedCodeGenerator extends AbstractSExecModel
 
 		// refresh the project to get external updates:
 
-		refreshTargetProject(entry);
+		efsHelper.refreshTargetProject(entry);
 	}
 
 	protected XpandExecutionContext createXpandContext(GeneratorEntry entry, Output output) {
@@ -172,14 +169,4 @@ public abstract class AbstractXpandBasedCodeGenerator extends AbstractSExecModel
 		return Collections.emptySet();
 	}
 
-	protected void refreshTargetProject(GeneratorEntry entry) {
-		try {
-			IProject project = EFSResourceFileSystemAccess.getTargetProject(entry);
-			if (project != null)
-				project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
-		} catch (CoreException e) {
-			e.printStackTrace();
-		}
-	}
-
 }

+ 57 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/EFSHelper.java

@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) 2016 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * 		committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.generator.core.impl;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.yakindu.sct.generator.core.library.OutletFeatureHelperImpl;
+import org.yakindu.sct.model.sgen.GeneratorEntry;
+
+/**
+ * @author Johannes Dicks - Initial contribution and API
+ *
+ */
+//FIXME !!! dependent classes are not useable in headless context
+public class EFSHelper {
+
+		public void refreshTargetProject(GeneratorEntry entry){
+			try {
+				IProject project = getTargetProject(entry);
+				if (project != null && project.isAccessible())
+					project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+			} catch (CoreException e) {
+				//FIXME !!! handle properly?!
+				e.printStackTrace();
+			}
+		}	
+		
+		/**
+		 * Returns an IProject for the configured target project. The
+		 * {@link IProject} is returned even if the project does not exist yet.
+		 * 
+		 * @param entry
+		 * @return
+		 */
+		public IProject getTargetProject(GeneratorEntry entry) {
+			String stringValue = new OutletFeatureHelperImpl().getTargetProjectValue(entry).getStringValue();
+			if (Platform.isRunning()) {
+				IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(stringValue);
+				return project;
+			} else
+				throw new IllegalStateException("The "+AbstractXpandBasedCodeGenerator.class.getSimpleName()+" needs a running eclipse.Platform" );
+		}
+
+}