@Override
  public IStatus transferSettings(IPath newWorkspaceRoot) {
    IPath currentWorkspace = Platform.getLocation();

    File srcDir =
        new File(
            currentWorkspace.toFile(), ".metadata/.plugins/org.eclipse.core.runtime/.settings");
    File destDir =
        new File(
            newWorkspaceRoot.toFile(), ".metadata/.plugins/org.eclipse.core.runtime/.settings");

    File[] srcSettings = srcDir.listFiles();

    if (!destDir.exists()) {
      if (!destDir.mkdirs())
        return new Status(IStatus.ERROR, LiferayUIPlugin.PLUGIN_ID, "can't create dirs");
    }

    for (File src : srcSettings) {
      File destSetting = new File(destDir.getAbsolutePath(), src.getName());

      if (destSetting.exists()) {
        if (!destSetting.delete()) {
          return new Status(IStatus.ERROR, LiferayUIPlugin.PLUGIN_ID, "can't delete settings file");
        }
      }

      FileUtil.copyFile(src, destSetting);
    }

    return Status.OK_STATUS;
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext )
   */
  public void stop(BundleContext context) throws Exception {
    // delete tmp folder
    File createDir = getDefault().getStateLocation().append("create").toFile(); // $NON-NLS-1$

    if (createDir.exists()) {
      FileUtil.deleteDir(createDir, true);
    }

    plugin = null;
    super.stop(context);
  }
  public static boolean isValidWorkspaceLocation(String location) {
    File workspaceDir = new File(location);

    File buildGradle = new File(workspaceDir, "build.gradle");
    File settingsGradle = new File(workspaceDir, "settings.gradle");
    File gradleProperties = new File(workspaceDir, "gradle.properties");

    if (!(buildGradle.exists() && settingsGradle.exists() && gradleProperties.exists())) {
      return false;
    }

    final String settingsContent = FileUtil.readContents(settingsGradle, true);

    return settingsContent != null && PATTERN_WORKSPACE_PLUGIN.matcher(settingsContent).matches();
  }
  private IStatus autoDeploy(IPath output) throws CoreException {
    IStatus retval = null;

    final IPath autoDeployPath = portalRuntime.getPortalBundle().getAutoDeployPath();
    final IPath statePath = portalRuntime.getPortalBundle().getModulesPath().append("state");

    if (autoDeployPath.toFile().exists()) {
      try {
        FileUtil.writeFileFromStream(
            autoDeployPath.append(output.lastSegment()).toFile(),
            new FileInputStream(output.toFile()));

        retval = Status.OK_STATUS;
      } catch (IOException e) {
        retval = LiferayServerCore.error("Unable to copy file to auto deploy folder", e);
      }
    }

    if (statePath.toFile().exists()) {
      FileUtil.deleteDir(statePath.toFile(), true);
    }

    return retval;
  }
  public static void clearWorkspace(String location) {
    File projectFile = new File(location, ".project");

    if (projectFile.exists()) {
      projectFile.delete();
    }

    File classpathFile = new File(location, ".classpath");

    if (classpathFile.exists()) classpathFile.delete();

    File settings = new File(location, ".settings");

    if (settings.exists() && settings.isDirectory()) {
      FileUtil.deleteDir(settings, true);
    }
  }
예제 #6
0
파일: SDK.java 프로젝트: petrep/liferay-ide
  public IPath createNewProject(
      String projectName,
      ArrayList<String> arguments,
      String type,
      String workingDir,
      IProgressMonitor monitor)
      throws CoreException {
    CreateHelper createHelper = new CreateHelper(this, monitor);

    final IPath pluginFolder = getLocation().append(getPluginFolder(type));

    final IPath newPath = pluginFolder.append(projectName + getPluginSuffix(type));

    String createScript = ISDKConstants.CREATE_BAT;

    if (!CoreUtil.isWindows()) {
      createScript = ISDKConstants.CREATE_SH;
    }

    final IPath createFilePath = pluginFolder.append(createScript);

    final File createFile = createFilePath.toFile();

    String originalCreateConetent = "";

    if (!CoreUtil.isWindows() && createFile.exists()) {
      originalCreateConetent = FileUtil.readContents(createFile, true);

      if (originalCreateConetent.contains("DisplayName=\\\"$2\\\"")) {
        String createContent =
            originalCreateConetent.replace("DisplayName=\\\"$2\\\"", "DisplayName=\"$2\"");

        try {
          FileUtil.writeFile(
              createFile,
              new ByteArrayInputStream(createContent.toString().getBytes("UTF-8")),
              null);
        } catch (Exception e) {
          SDKCorePlugin.logError(e);
        }
      }
    }

    createHelper.runTarget(createFilePath, arguments, workingDir);

    if (!newPath.toFile().exists()) {
      throw new CoreException(
          SDKCorePlugin.createErrorStatus("Create script did not complete successfully."));
    }

    if (!CoreUtil.isNullOrEmpty(originalCreateConetent)) {
      try {
        FileUtil.writeFile(
            createFile,
            new ByteArrayInputStream(originalCreateConetent.toString().getBytes("UTF-8")),
            null);
      } catch (Exception e) {
        SDKCorePlugin.logError(e);
      }
    }

    return newPath;
  }
예제 #7
0
  private static void initializeLautRunner() {
    String lautRunnerPath = System.getProperty(LAUT_PATH);

    if (lautRunnerPath != null) {
      File lautRunnerFile = new File(lautRunnerPath);

      if (!lautRunnerFile.exists()) {
        lautRunnerPath = null;
      }
    }

    if (lautRunnerPath == null) {
      try {
        final Bundle lautRunnerBundle = AlloyCore.getDefault().getBundle();
        URL lautUrl = null;

        if (lautRunnerBundle == null) {
          AlloyCore.logError("Unable to find laut bundle.");
        } else {
          final Enumeration<URL> lautEntries =
              lautRunnerBundle.findEntries("/" + LAUT_ENTRY, "/", false);

          if (lautEntries == null || !lautEntries.hasMoreElements()) {
            final Enumeration<URL> lautZipEntries =
                lautRunnerBundle.findEntries("/", LAUT_ZIP, false);

            if (lautZipEntries != null && lautZipEntries.hasMoreElements()) {
              final File lautZipFile =
                  new File(FileLocator.toFileURL(lautZipEntries.nextElement()).getFile());

              final File lautBundleDir = lautZipFile.getParentFile();

              File lautDir = new File(lautBundleDir, LAUT_ENTRY);

              if (!lautBundleDir.canWrite()) {
                lautDir = AlloyCore.getDefault().getStateLocation().append(LAUT_ENTRY).toFile();

                FileUtil.deleteDir(lautDir, true);
              }

              ZipUtil.unzip(lautZipFile, lautDir.getParentFile());

              new File(lautBundleDir, "laut").renameTo(lautDir);

              final Enumeration<URL> lautPathEntries =
                  lautRunnerBundle.findEntries("/" + LAUT_ENTRY, "/", false);
              lautUrl = lautPathEntries.nextElement();
            }
          } else {
            lautUrl = lautEntries.nextElement();
          }

          if (lautUrl != null) {
            final File lautRunnerDir = new File(FileLocator.toFileURL(lautUrl).getFile());
            final String lautRunnerDirPath = lautRunnerDir.getAbsolutePath();

            System.setProperty(LAUT_PATH, lautRunnerDirPath);
            setSDKExecutableFlags(new Path(lautRunnerDirPath));
          }
        }
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }