Author: dgolovin
Date: 2007-08-03 18:13:35 -0400 (Fri, 03 Aug 2007)
New Revision: 2903
Added:
trunk/jst/plugins/org.jboss.tools.jst.firstrun/.classpath
trunk/jst/plugins/org.jboss.tools.jst.firstrun/.project
trunk/jst/plugins/org.jboss.tools.jst.firstrun/META-INF/
trunk/jst/plugins/org.jboss.tools.jst.firstrun/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.firstrun/build.properties
trunk/jst/plugins/org.jboss.tools.jst.firstrun/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/jst/
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/jst/firstrun/
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/jst/firstrun/JBossASAdapterInitializer.java
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/jst/firstrun/JstFirstRunPlugin.java
Log:
JBoss AS 4.2.0 initialization during startup
Added: trunk/jst/plugins/org.jboss.tools.jst.firstrun/.classpath
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.firstrun/.classpath (rev
0)
+++ trunk/jst/plugins/org.jboss.tools.jst.firstrun/.classpath 2007-08-03 22:13:35 UTC (rev
2903)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/jst/plugins/org.jboss.tools.jst.firstrun/.project
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.firstrun/.project (rev
0)
+++ trunk/jst/plugins/org.jboss.tools.jst.firstrun/.project 2007-08-03 22:13:35 UTC (rev
2903)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.jboss.tools.jst.firstrun</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/jst/plugins/org.jboss.tools.jst.firstrun/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.firstrun/META-INF/MANIFEST.MF
(rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.firstrun/META-INF/MANIFEST.MF 2007-08-03
22:13:35 UTC (rev 2903)
@@ -0,0 +1,16 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: JBoss AS Initialization Plug-in
+Bundle-SymbolicName: org.jboss.tools.jst.firstrun;singleton:=true
+Bundle-Version: 2.0.0
+Bundle-Vendor: Red Hat, Inc.
+Require-Bundle: org.eclipse.ui.workbench,
+ org.eclipse.wst.server.core,
+ org.eclipse.core.runtime,
+ org.jboss.tools.common,
+ org.eclipse.core.resources,
+ org.eclipse.jdt.launching,
+ org.eclipse.jface
+Bundle-Activator: org.jboss.tools.jst.firstrun.JstFirstRunPlugin
+Eclipse-LazyStart: true
+Export-Package: org.jboss.tools.jst.firstrun
Added: trunk/jst/plugins/org.jboss.tools.jst.firstrun/build.properties
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.firstrun/build.properties
(rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.firstrun/build.properties 2007-08-03 22:13:35
UTC (rev 2903)
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
Added: trunk/jst/plugins/org.jboss.tools.jst.firstrun/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.firstrun/plugin.xml (rev
0)
+++ trunk/jst/plugins/org.jboss.tools.jst.firstrun/plugin.xml 2007-08-03 22:13:35 UTC (rev
2903)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.startup">
+ <startup
+ class="org.jboss.tools.jst.firstrun.JBossASAdapterInitializer">
+ </startup>
+ </extension>
+
+</plugin>
Added:
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/jst/firstrun/JBossASAdapterInitializer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/jst/firstrun/JBossASAdapterInitializer.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/jst/firstrun/JBossASAdapterInitializer.java 2007-08-03
22:13:35 UTC (rev 2903)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.jst.firstrun;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.ui.IStartup;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IRuntimeType;
+import org.eclipse.wst.server.core.IRuntimeWorkingCopy;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerType;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.eclipse.wst.server.core.internal.RuntimeWorkingCopy;
+
+/**
+ * @author eskimo
+ *
+ */
+public class JBossASAdapterInitializer implements IStartup {
+
+ public static final String JBOSS_AS_HOME = "../../../../jboss-eap/jboss-as";
// JBoss AS home directory (relative to plugin)- <RHDS_HOME>/jbossas.
+
+ public static final String JBOSS_AS_RUNTIME_TYPE_ID =
"org.jboss.ide.eclipse.as.runtime.42";
+ public static final String JBOSS_AS_TYPE_ID = "org.jboss.ide.eclipse.as.42";
+ public static final String JBOSS_AS_NAME = "JBoss Application Server 4.2";
+ public static final String JBOSS_AS_HOST = "localhost";
+ public static final String JBOSS_AS_DEFAULT_CONFIGURATION_NAME = "default";
+
+ public static final String FIRST_START_PREFERENCE_NAME = "FIRST_START";
+
+ /**
+ * @see org.eclipse.ui.IStartup#earlyStartup()
+ */
+ public void earlyStartup() {
+
+ try {
+
+ JstFirstRunPlugin.getDefault().getPreferenceStore().setDefault(FIRST_START_PREFERENCE_NAME,
true);
+ boolean firstStart =
JstFirstRunPlugin.getDefault().getPreferenceStore().getBoolean(FIRST_START_PREFERENCE_NAME);
+ if(!firstStart) {
+ return;
+ }
+ JstFirstRunPlugin.getDefault().getPreferenceStore().setValue(FIRST_START_PREFERENCE_NAME,
false);
+
+ String jbossASLocation = null;
+ String pluginLocation =
FileLocator.resolve(JstFirstRunPlugin.getDefault().getBundle().getEntry("/")).getPath();
+ File jbossASDir = new File(pluginLocation, JBOSS_AS_HOME);
+ if(jbossASDir.isDirectory()) {
+ jbossASLocation = jbossASDir.getAbsolutePath();
+ } else {
+ return;
+ }
+
+ IPath jbossAsLocationPath = new Path(jbossASLocation);
+ String type = null;
+ String version = null;
+
+ IServer[] servers = ServerCore.getServers();
+ for(int i=0; i<servers.length; i++) {
+ IRuntime runtime = servers[i].getRuntime();
+ if(runtime!=null && runtime.getLocation().equals(jbossAsLocationPath)) {
+ return;
+ }
+ }
+
+ IRuntimeWorkingCopy runtime = null;
+ IRuntime[] runtimes = ServerCore.getRuntimes();
+ String runtimeId = null;
+ for(int i=0; i<runtimes.length; i++) {
+ if(runtimes[0].getLocation().equals(jbossASLocation)) {
+ runtime = runtimes[0].createWorkingCopy();
+ runtimeId = null;
+ break;
+ }
+ }
+
+ IProgressMonitor progressMonitor = new NullProgressMonitor();
+ if(runtime==null) {
+ IRuntimeType[] runtimeTypes = ServerUtil.getRuntimeTypes(type, version,
JBOSS_AS_RUNTIME_TYPE_ID);
+ if(runtimeTypes.length>0) {
+ runtime = runtimeTypes[0].createRuntime(runtimeId, progressMonitor);
+ runtime.setLocation(jbossAsLocationPath);
+ IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();
+ // IJBossServerRuntime.PROPERTY_VM_ID
+ ((RuntimeWorkingCopy)runtime).setAttribute("PROPERTY_VM_ID",
defaultVM.getId());
+ // IJBossServerRuntime.PROPERTY_VM_TYPE_ID
+ ((RuntimeWorkingCopy)runtime).setAttribute("PROPERTY_VM_TYPE_ID",
defaultVM.getVMInstallType().getId());
+ // IJBossServerRuntime.PROPERTY_CONFIGURATION_NAME
+ ((RuntimeWorkingCopy)runtime).setAttribute("org.jboss.ide.eclipse.as.core.runtime.configurationName",
JBOSS_AS_DEFAULT_CONFIGURATION_NAME);
+
+ runtime.save(false, progressMonitor);
+ }
+ }
+
+ if(runtime!=null) {
+ IServerType serverType = ServerCore.findServerType(JBOSS_AS_TYPE_ID);
+ IServerWorkingCopy server = serverType.createServer(null, null, runtime,
progressMonitor);
+
+ server.setHost(JBOSS_AS_HOST);
+ server.setName(JBOSS_AS_NAME);
+ server.save(false, progressMonitor);
+ }
+ } catch (CoreException e) {
+ JstFirstRunPlugin.getPluginLog().logError("Can't create new JBoss
Server.", e);
+ } catch (IOException e) {
+ JstFirstRunPlugin.getPluginLog().logError("Can't create new JBoss
Server.", e);
+ }
+ }
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/jst/firstrun/JstFirstRunPlugin.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/jst/firstrun/JstFirstRunPlugin.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.firstrun/src/org/jboss/tools/jst/firstrun/JstFirstRunPlugin.java 2007-08-03
22:13:35 UTC (rev 2903)
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.jst.firstrun;
+
+import org.jboss.tools.common.log.BaseUIPlugin;
+import org.jboss.tools.common.log.IPluginLog;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author eskimo
+ *
+ */
+public class JstFirstRunPlugin extends BaseUIPlugin {
+
+ static private JstFirstRunPlugin instance;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ instance = this;
+ }
+
+ /**
+ * @return
+ */
+ public static IPluginLog getPluginLog() {
+ return (IPluginLog)instance;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public static JstFirstRunPlugin getDefault() {
+ return instance;
+ }
+}