Explorar o código

#815 removed check for directory name sc_examples (#816)

Andreas Mülder %!s(int64=9) %!d(string=hai) anos
pai
achega
a2b4f699e4

+ 6 - 1
plugins/org.yakindu.sct.examples.wizard/src/org/yakindu/sct/examples/wizard/preferences/ExamplesPreferenceInitializer.java

@@ -10,6 +10,8 @@
  */
 package org.yakindu.sct.examples.wizard.preferences;
 
+import java.io.File;
+
 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.yakindu.sct.examples.wizard.ExampleActivator;
@@ -21,10 +23,13 @@ import org.yakindu.sct.examples.wizard.ExampleActivator;
  */
 public class ExamplesPreferenceInitializer extends AbstractPreferenceInitializer {
 
+	private static final String EXAMPLES = "sct_examples";
+
 	@Override
 	public void initializeDefaultPreferences() {
 		String property = System.getProperty("user.home");
-		getPreferenceStore().setDefault(ExamplesPreferenceConstants.STORAGE_LOCATION, property);
+		getPreferenceStore().setDefault(ExamplesPreferenceConstants.STORAGE_LOCATION,
+				property + File.separator + EXAMPLES);
 	}
 
 	protected IPreferenceStore getPreferenceStore() {

+ 8 - 13
plugins/org.yakindu.sct.examples.wizard/src/org/yakindu/sct/examples/wizard/service/git/GitRepositoryExampleService.java

@@ -12,7 +12,6 @@ package org.yakindu.sct.examples.wizard.service.git;
 
 import java.io.File;
 import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
 import java.nio.file.DirectoryStream;
 import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
@@ -25,7 +24,6 @@ import java.util.List;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
@@ -34,6 +32,7 @@ import org.eclipse.jgit.api.FetchCommand;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.PullResult;
 import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.errors.RepositoryNotFoundException;
 import org.eclipse.jgit.transport.FetchResult;
 import org.eclipse.jgit.transport.TrackingRefUpdate;
 import org.eclipse.ui.dialogs.IOverwriteQuery;
@@ -71,7 +70,7 @@ public class GitRepositoryExampleService implements IExampleService {
 	private java.nio.file.Path gitRepo;
 
 	public GitRepositoryExampleService() {
-		gitRepo = java.nio.file.Paths.get(getStorageLocation(), "sct_examples");
+		gitRepo = java.nio.file.Paths.get(getStorageLocation());
 	}
 
 	private String getStorageLocation() {
@@ -183,11 +182,7 @@ public class GitRepositoryExampleService implements IExampleService {
 					}, filesToImport);
 			io.run(monitor);
 			project.open(monitor);
-		} catch (CoreException e) {
-			e.printStackTrace();
-		} catch (InvocationTargetException e) {
-			e.printStackTrace();
-		} catch (InterruptedException e) {
+		} catch (Exception e) {
 			e.printStackTrace();
 		}
 	}
@@ -204,7 +199,7 @@ public class GitRepositoryExampleService implements IExampleService {
 	}
 
 	public void deleteFolder(java.nio.file.Path path) throws IOException {
-		if(!Files.exists(path))
+		if (!Files.exists(path))
 			return;
 		Files.walkFileTree(path, new SimpleFileVisitor<java.nio.file.Path>() {
 			@Override
@@ -228,12 +223,12 @@ public class GitRepositoryExampleService implements IExampleService {
 			FetchResult result = fetch.setProgressMonitor(new EclipseGitProgressTransformer(monitor)).setDryRun(true)
 					.call();
 			Collection<TrackingRefUpdate> trackingRefUpdates = result.getTrackingRefUpdates();
-			for (TrackingRefUpdate trackingRefUpdate : trackingRefUpdates) {
-				System.out.println(trackingRefUpdate);
-			}
 			return trackingRefUpdates.size() == 0;
-
+		} catch (RepositoryNotFoundException ex) {
+			// This is the case when the examples are imported manually
+			return true;
 		} catch (Exception ex) {
+			ex.printStackTrace();
 			return true;
 		}
 	}