コード例 #1
0
 private void openError(EditorState editor, String message) {
   try {
     Status status = new Status(IStatus.ERROR, RuntimeActivator.PLUGIN_ID, message);
     ErrorDialog.openError(editor.getEditor().getSite().getShell(), displayCaption, null, status);
   } catch (RuntimeException e) {
     Environment.logException("Problem reporting error: " + message, e);
   }
 }
コード例 #2
0
  private void doFinish(
      String appName,
      String projectName,
      boolean isMysqlSelected,
      String host,
      String user,
      String pass,
      String name,
      String mode,
      String file,
      String tomcatpath,
      String smtphost,
      String smtpport,
      String smtpuser,
      String smtppass,
      IProgressMonitor monitor)
      throws IOException, CoreException {
    final int TASK_COUNT = 3;
    lastProject = null;
    monitor.beginTask("Creating " + appName + " application", TASK_COUNT);

    // EditorIOAgent agent = new EditorIOAgent();
    // agent.setAlwaysActivateConsole(true);
    // Context context = new Context(Environment.getTermFactory(), agent);
    // context.registerClassLoader(make_permissive.class.getClassLoader());
    // sdf2imp.init(context);

    monitor.setTaskName("Creating Eclipse project");
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = lastProject = workspace.getRoot().getProject(projectName);
    project.create(null);
    project.open(null);
    monitor.worked(1);

    monitor.setTaskName("Copying example application files");

    // agent.setWorkingDir(project.getLocation().toOSString());
    String plugindir =
        webdsl.WebDSLEditorWizard.class
            .getProtectionDomain()
            .getCodeSource()
            .getLocation()
            .getFile();
    if (Platform.getOS().equals(Platform.OS_WIN32)) { // FIXME: proper paths on Windows
      plugindir = plugindir.substring(1);
      // jar2 = jar2.substring(1);
      // jar3 = jar3.substring(1);
    }
    /*
    if (!jar1.endsWith(".jar")) { // ensure correct jar at development time
    	String jar1a = jar1 + "/../strategoxt.jar";
    	if (new File(jar1a).exists()) jar1 = jar1a;
    	jar1a = jar1 + "/java/strategoxt.jar";
    	if (new File(jar1a).exists()) jar1 = jar1a;
    }*/
    System.out.println("path: " + plugindir);

    try {
      String appinifilename = project.getLocation() + "/application.ini";
      System.out.println(appinifilename);
      BufferedWriter out = new BufferedWriter(new FileWriter(appinifilename));
      out.write("appname=" + appName + "\n");
      out.write("backend=servlet\n");
      out.write("sessiontimeout=120\n");
      out.write("smtphost=" + smtphost + "\n");
      out.write("smtpport=" + smtpport + "\n");
      out.write("smtpuser="******"\n");
      out.write("smtppass="******"\n");
      out.write("tomcatpath=" + tomcatpath + "\n");
      if (isMysqlSelected) {
        out.write("dbserver=" + host + "\n");
        out.write("dbuser="******"\n");
        out.write("dbpassword="******"\n");
        out.write("dbname=" + name + "\n");
        out.write("dbmode=" + mode + "\n");
      } else {
        out.write("db=sqlite\n");
        out.write("dbfile=" + file + "\n");
        out.write("dbmode=" + mode + "\n");
      }
      out.close();
    } catch (IOException e) {
      Environment.logException(e);
      throw e;
    }

    copyFile(
        plugindir + "webdsl-template/new_project/templates.app",
        project.getLocation() + "/templates.app");
    copyFile(
        plugindir + "webdsl-template/new_project/APPLICATION_NAME.app",
        project.getLocation() + "/" + appName + ".app");
    createDirs(project.getLocation() + "/images");
    copyFile(
        plugindir + "webdsl-template/new_project/images/logosmall.png",
        project.getLocation() + "/images/logosmall.png");
    createDirs(project.getLocation() + "/stylesheets");
    copyFile(
        plugindir + "webdsl-template/new_project/stylesheets/common_.css",
        project.getLocation() + "/stylesheets/common_.css");

    monitor.worked(1);

    StringBuffer ant = new StringBuffer();
    ant.append("<project name=\"webdsl-eclipse-plugin\" default=\"plugin-eclipse-build\">\n");
    // ant.append("\t<property name=\"plugindir\" value=\""+plugindir+"\" />\n");
    ant.append(
        "\t<fail unless=\"plugindir\" message=\"WebDSL plugin is not correctly installed. The 'plugindir' property is not available.\" />\n");
    ant.append("\t<property name=\"templatedir\" value=\"${plugindir}/webdsl-template\"/>\n");
    ant.append("\t<property name=\"currentdir\" value=\"${basedir}\"/>\n");
    ant.append("\t<property name=\"webdsl-java-cp\" value=\"${plugindir}/include/webdsl.jar\"/>\n");
    ant.append("\t<property name=\"webdslexec\" value=\"java\"/>\n");
    ant.append("\t<import file=\"${plugindir}/webdsl-template/webdsl-build.xml\"/>\n");

    ant.append("\t<target name=\"plugin-eclipse-build\">\n");
    ant.append("\t\t<antcall target=\"eclipse-build\"/>\n");
    ant.append("\t</target>\n");

    ant.append("\t<target name=\"plugin-build\">\n");
    ant.append("\t\t<property name=\"buildoptions\" value=\"build\" />\n");
    ant.append("\t\t<antcall target=\"command\"/>\n");
    ant.append("\t</target>\n");

    ant.append("\t<target name=\"plugin-run\">\n");
    ant.append("\t\t<property name=\"buildoptions\" value=\"run\" />\n");
    ant.append("\t\t<antcall target=\"command\"/>\n");
    ant.append("\t</target>\n");

    ant.append("\t<target name=\"plugin-deploy\">\n");
    ant.append("\t\t<property name=\"buildoptions\" value=\"deploy\" />\n");
    ant.append("\t\t<antcall target=\"command\"/>\n");
    ant.append("\t</target>\n");

    ant.append("\t<target name=\"plugin-tomcatdeploy\">\n");
    ant.append("\t\t<property name=\"buildoptions\" value=\"tomcatdeploy\" />\n");
    ant.append("\t\t<antcall target=\"command\"/>\n");
    ant.append("\t</target>\n");

    ant.append("\t<target name=\"plugin-cleanall\">\n");
    ant.append("\t\t<property name=\"buildoptions\" value=\"cleanall\" />\n");
    ant.append("\t\t<antcall target=\"command\"/>\n");
    ant.append("\t</target>\n");

    ant.append("</project>");

    writeStringToFile(ant.toString(), project.getLocation() + "/build.xml");

    // create build launch file to make sure ant uses same jre instance as eclipse, otherwise the
    // plugindir property provider won't work
    StringBuffer buildLaunchFile = new StringBuffer();
    buildLaunchFile.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
    buildLaunchFile.append(
        "<launchConfiguration type=\"org.eclipse.ant.AntLaunchConfigurationType\">\n");
    buildLaunchFile.append(
        "\t<booleanAttribute key=\"org.eclipse.ant.ui.DEFAULT_VM_INSTALL\" value=\"false\"/>\n");
    buildLaunchFile.append(
        "\t<listAttribute key=\"org.eclipse.debug.core.MAPPED_RESOURCE_PATHS\">\n");
    buildLaunchFile.append("\t\t<listEntry value=\"/" + appName + "/build.xml\"/>\n");
    buildLaunchFile.append("\t</listAttribute>\n");
    buildLaunchFile.append(
        "\t<listAttribute key=\"org.eclipse.debug.core.MAPPED_RESOURCE_TYPES\">\n");
    buildLaunchFile.append("\t\t<listEntry value=\"1\"/>\n");
    buildLaunchFile.append("\t</listAttribute>\n");
    buildLaunchFile.append(
        "\t<stringAttribute key=\"org.eclipse.jdt.launching.CLASSPATH_PROVIDER\" value=\"org.eclipse.ant.ui.AntClasspathProvider\"/>\n");
    buildLaunchFile.append(
        "\t<stringAttribute key=\"org.eclipse.jdt.launching.PROJECT_ATTR\" value=\""
            + appName
            + "\"/>\n");
    buildLaunchFile.append(
        "\t<stringAttribute key=\"org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER\" value=\"org.eclipse.ant.ui.AntClasspathProvider\"/>\n");
    buildLaunchFile.append(
        "\t<stringAttribute key=\"org.eclipse.ui.externaltools.ATTR_ANT_TARGETS\" value=\"plugin-eclipse-build,\"/>\n");
    buildLaunchFile.append(
        "\t<stringAttribute key=\"org.eclipse.ui.externaltools.ATTR_LOCATION\" value=\"${workspace_loc:/"
            + appName
            + "/build.xml}\"/>\n");
    buildLaunchFile.append(
        "\t<stringAttribute key=\"process_factory_id\" value=\"org.eclipse.ant.ui.remoteAntProcessFactory\"/>\n");
    buildLaunchFile.append("</launchConfiguration>\n");
    writeStringToFile(
        buildLaunchFile.toString(), project.getLocation() + "/" + appName + " build.xml.launch");

    // overwrite .project file with correct settings
    StringBuffer projectFile = new StringBuffer();
    projectFile.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    projectFile.append("<projectDescription>\n");
    projectFile.append("\t<name>" + projectName + "</name>\n");
    projectFile.append("\t<buildSpec>\n");
    projectFile.append("\t\t<buildCommand>\n");
    projectFile.append("\t\t\t<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>\n");
    projectFile.append("\t\t\t<triggers>full,incremental,</triggers>\n");
    projectFile.append("\t\t\t<arguments><dictionary>\n");
    projectFile.append("\t\t\t\t<key>LaunchConfigHandle</key>\n");
    projectFile.append(
        "\t\t\t\t<value>&lt;project&gt;/" + projectName + " build.xml.launch</value>\n");
    projectFile.append("\t\t\t</dictionary></arguments>\n");
    projectFile.append("\t\t</buildCommand>\n");
    projectFile.append("\t\t<buildCommand>\n");
    projectFile.append("\t\t\t<name>org.eclipse.jdt.core.javabuilder</name>\n");
    projectFile.append("\t\t</buildCommand>\n");
    projectFile.append("\t\t<buildCommand>\n");
    projectFile.append("\t\t\t<name>org.eclipse.wst.common.project.facet.core.builder</name>\n");
    projectFile.append("\t\t</buildCommand>\n");
    // projectFile.append("\t\t<buildCommand>\n");
    // projectFile.append("\t\t\t<name>org.eclipse.wst.validation.validationbuilder</name>\n");
    // projectFile.append("\t\t</buildCommand>\n");
    projectFile.append("\t</buildSpec>\n");
    projectFile.append("\t<natures>\n");
    projectFile.append("\t\t<nature>org.eclipse.jdt.core.javanature</nature>\n");
    projectFile.append("\t\t<nature>org.eclipse.wst.common.project.facet.core.nature</nature>\n");
    projectFile.append("\t\t<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>\n");
    projectFile.append("\t\t<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>\n");
    projectFile.append("\t</natures>\n");
    projectFile.append("</projectDescription>\n");
    writeStringToFile(projectFile.toString(), project.getLocation() + "/.project");

    // write a .classpath for java nature of project
    StringBuffer classpathFile = new StringBuffer();
    classpathFile.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    classpathFile.append("<classpath>\n");
    classpathFile.append("\t<classpathentry kind=\"src\" path=\".servletapp/src\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"con\" path=\"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"con\" path=\"org.eclipse.jst.j2ee.internal.web.container\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"con\" path=\"org.eclipse.jst.j2ee.internal.module.container\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"output\" path=\"WebContent/WEB-INF/classes\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/antlr.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/asm-attrs.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/asm.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/c3p0-0.9.1.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/cglib.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/commons-codec-1.3.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/commons-collections.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/commons-fileupload-1.2.1.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/commons-io-1.4.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/commons-lang-2.3.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/commons-logging.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/dom4j.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/ehcache-1.2.3.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/ejb3-persistence.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/hibernate-annotations.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/hibernate-commons-annotations.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/hibernate-search-3.1.1.GA.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/hibernate3.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/icu4j-3_8.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/jasypt-1.3.1.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/javaee.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/javassist-3.4.GA.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/jcaptcha-all-1.0-RC6.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/jta.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/junit.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/log4j.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/lucene-core-2.4.1.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/mail.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/markdownj.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/mysql-connector-java-5.1.6-bin.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/slf4j-api.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/slf4j-log4j12.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/sqlite-jdbc-3.6.17.1.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/strategoxt.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/urlrewrite.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/webdsl-support.jar\"/>\n");
    classpathFile.append(
        "\t<classpathentry kind=\"lib\" path=\".servletapp/bin/WEB-INF/lib/xercesImpl.jar\"/>\n");
    classpathFile.append("</classpath>\n");
    writeStringToFile(classpathFile.toString(), project.getLocation() + "/.classpath");

    // write .settings/* files
    createDirs(project.getLocation() + "/.settings");

    StringBuffer jdtprefsFile = new StringBuffer();
    jdtprefsFile.append("eclipse.preferences.version=1\n");
    jdtprefsFile.append("org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\n");
    jdtprefsFile.append("org.eclipse.jdt.core.compiler.compliance=1.6\n");
    jdtprefsFile.append("org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\n");
    jdtprefsFile.append("org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\n");
    jdtprefsFile.append("org.eclipse.jdt.core.compiler.source=1.6\n");
    writeStringToFile(
        jdtprefsFile.toString(), project.getLocation() + "/.settings/org.eclipse.jdt.core.prefs");

    StringBuffer wstcomponentFile = new StringBuffer();
    wstcomponentFile.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    wstcomponentFile.append("<project-modules id=\"moduleCoreId\" project-version=\"1.5.0\">\n");
    wstcomponentFile.append("\t<wb-module deploy-name=\"" + projectName + "\">\n");
    wstcomponentFile.append("\t\t<wb-resource deploy-path=\"/\" source-path=\"/WebContent\"/>\n");
    wstcomponentFile.append(
        "\t\t<wb-resource deploy-path=\"/WEB-INF/classes\" source-path=\"/.servletapp/src\"/>\n");
    wstcomponentFile.append(
        "\t\t<property name=\"context-root\" value=\"" + projectName + "\"/>\n");
    wstcomponentFile.append("\t\t<property name=\"java-output-path\"/>\n");
    wstcomponentFile.append("\t</wb-module>\n");
    wstcomponentFile.append("</project-modules>\n");
    writeStringToFile(
        wstcomponentFile.toString(),
        project.getLocation() + "/.settings/org.eclipse.wst.common.component");

    StringBuffer wstfacetFile = new StringBuffer();
    wstfacetFile.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    wstfacetFile.append("<faceted-project>\n");
    wstfacetFile.append("\t<installed facet=\"jst.java\" version=\"6.0\"/>\n");
    wstfacetFile.append("\t<installed facet=\"jst.web\" version=\"2.4\"/>\n");
    wstfacetFile.append("</faceted-project>\n");
    writeStringToFile(
        wstfacetFile.toString(),
        project.getLocation() + "/.settings/org.eclipse.wst.common.project.facet.core.xml");

    /*
    *
    	monitor.worked(3);*/
    /*
    monitor.setTaskName("Acquiring workspace lock"); // need root lock for builder
    IWorkspaceRoot root = project.getWorkspace().getRoot();
    Job.getJobManager().beginRule(root, monitor); // avoid ant builder launching
    try {
    	monitor.setTaskName("Acquiring environment lock");
    	monitor.worked(1);
    	synchronized (Environment.getSyncRoot()) { // avoid background editor loading
    		monitor.setTaskName("Loading new resources");
    		project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    		monitor.worked(1);

    		monitor.setTaskName("Building and loading example editor");
    		project.build(IncrementalProjectBuilder.FULL_BUILD, null);
    		monitor.worked(6);

    		// TODO: Optimize - don't reload editor (already done from Ant file)
    		// DynamicDescriptorLoader.getInstance().forceNoUpdate(descriptor);
    		monitor.setTaskName("Loading editor");
    		IResource descriptor = project.findMember("include/" + languageName + ".packed.esv");
    		DynamicDescriptorLoader.getInstance().forceUpdate(descriptor);
    		monitor.worked(2);

    		//project.refreshLocal(DEPTH_INFINITE, new NullProgressMonitor());
    		monitor.worked(1);
    	}
    } finally {
    	Job.getJobManager().endRule(root);
    }

    monitor.setTaskName("Opening editor tabs");
    Display display = getShell().getDisplay();
    EditorState.asyncOpenEditor(display, project.getFile("/trans/" + toStrategoName(languageName) +  ".str"), true);
    monitor.worked(2);
    EditorState.asyncOpenEditor(display, project.getFile("/editor/" + languageName +  ".main.esv"), true);
    monitor.worked(1);
    EditorState.asyncOpenEditor(display, project.getFile("/syntax/" + languageName +  ".sdf"), true);
    monitor.worked(1);
    EditorState.asyncOpenEditor(display, project.getFile("/test/example." + extensions.split(",")[0]), false);*/
    refreshProject(project);

    monitor.setTaskName("Opening editor tabs");

    Display display = getShell().getDisplay();
    EditorState.asyncOpenEditor(display, project.getFile("templates.app"), true);
    EditorState.asyncOpenEditor(display, project.getFile(appName + ".app"), true);
    monitor.worked(1);
  }