Skip to content

Commit

Permalink
Add bundled sdk detector. Add initial form for adding go sdk to a pro…
Browse files Browse the repository at this point in the history
…ject. added initial linux packaging. Added scripted packaging
  • Loading branch information
mtoader committed Jul 30, 2011
1 parent bf61761 commit a9ee455
Show file tree
Hide file tree
Showing 13 changed files with 465 additions and 38 deletions.
117 changes: 117 additions & 0 deletions go-ide/package_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash

SOURCE_PATH_GO=~/Tools/google-go/release/
SOURCE_PATH_IDEA=~/Work/IntellijIdea/idea/
SOURCE_PATH_GO_PLUGIN=~/Work/google-go-language/

RELEASE_TAG_GO="release.r58.1"
RELEASE_TAG_IDEA=idea/107.322

function validate_go_sdk_location {

if [ ! -d "${SOURCE_PATH_GO}" ]; then
echo "Error: '${SOURCE_PATH_GO}' is not a folder"
exit 1
fi

if [ ! -d "${SOURCE_PATH_GO}/.hg" ]; then
echo "Error: '${SOURCE_PATH_GO}' is not a go checkout folder (is missing Mercurial metadata)"
exit 1
fi

pushd "${SOURCE_PATH_GO}" >/dev/null
ACTUAL_RELEASE_TAG_GO=`hg identify -t`
if [ "xrelease ${RELEASE_TAG_GO}" != "x${ACTUAL_RELEASE_TAG_GO}" ]; then
echo "Error: Go Source code is at the wrong tag: ${ACTUAL_RELEASE_TAG_GO}."
echo -e " Try this:"
echo -e "\tpushd '${SOURCE_PATH_GO}' && hg pull && hg update -r ${RELEASE_TAG_GO} && popd"
exit 1
fi

echo "GOOD: Go SDK sources are at the proper release ('${RELEASE_TAG_GO}' vs '${ACTUAL_RELEASE_TAG_GO}')"
popd >/dev/null
}

function validate_idea_community_location() {

if [ ! -d "$SOURCE_PATH_IDEA" ]; then
echo "Error: '$SOURCE_PATH_IDEA' is not a folder"
exit 1
fi

if [ ! -d "$SOURCE_PATH_IDEA/.git" ]; then
echo "Error: '$SOURCE_PATH_IDEA' is not a idea checkout folder (is missing Git metadata)"
exit 1
fi

pushd "$SOURCE_PATH_IDEA" >/dev/null
ACTUAL_RELEASE_TAG_IDEA=`git describe`
if [ "x$RELEASE_TAG_IDEA" != "x$ACTUAL_RELEASE_TAG_IDEA" ]; then
echo "Error: Intellij Idea Community source tree is at the wrong tag: $ACTUAL_RELEASE_TAG_IDEA"
echo -e " Try this:"
echo -e "\tpushd '$SOURCE_PATH_IDEA' && git pull && git checkout $RELEASE_TAG_IDEA && popd"
exit 1
fi

echo "GOOD: Intellij Idea Community source tree is at the proper release ('$RELEASE_TAG_IDEA' vs '$ACTUAL_RELEASE_TAG_IDEA')"
popd >/dev/null
}

function build_go_sdk() {
echo "Clean building Go Sdk"

pushd "$SOURCE_PATH_GO/src"

# fixup for when you also have a weekly go installed inside on your system.
/home/mtoader/Tools/google-go/release/bin
PATH=${SOURCE_PATH_GO}bin:$PATH

export PATH
# call the build
echo $PATH
./clean.bash && ./all.bash && popd

# rm -r $IDEASOURCEPATH/build/conf/mac/go-sdk
# cp -r $GOSOURCEPATH $IDEASOURCEPATH/build/conf/mac/go-sdk
}

function build_idea_community() {
cp "$SOURCE_PATH_GO_PLUGIN/go-ide/resources/idea_community_{about,logo}.png" "$SOURCE_PATH_IDEA/community-resources/src"

echo "Cleanly building Idea Community"
pushd ${SOURCE_PATH_IDEA}

# the default build target in Intellij Community will do a clean,build
ant
}

validate_go_sdk_location
validate_idea_community_location

build_go_sdk && build_idea_community
#build_idea_community

exit 0;

# Build the go sdk
cd $GOSOURCEPATH/src
./all.bash
rm -r $IDEASOURCEPATH/build/conf/mac/go-sdk
cp -r $GOSOURCEPATH $IDEASOURCEPATH/build/conf/mac/go-sdk

# Copy Go logo and about images
cp $PLUGINSOURCEPATH/go-ide/resources/idea_community_about.png $IDEASOURCEPATH/community-resources/src/
cp $PLUGINSOURCEPATH/go-ide/resources/idea_community_logo.png $IDEASOURCEPATH/community-resources/src/

cd $IDEASOURCEPATH
ant build
VERSION=$(cat build.txt)
cp $IDEASOURCEPATH/out/artifacts/ideaIC-$VERSION.mac.zip $PLUGINSOURCEPATH/go-ide
cd $PLUGINSOURCEPATH/go-ide
rm -r Community\ Edition-IC-$VERSION.app
unzip ideaIC-$VERSION.mac.zip

unzip ../google-go-language.zip -d Community\ Edition-IC-$VERSION.app/plugins
rm ideaIC-$VERSION.mac.zip

echo "Now open up dmgCreator to make the dmg."
58 changes: 58 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<project name="Idea Google Go language scripted build file" default="package" basedir=".">

<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="."/>
<property name="dist" location="dist"/>
<property name="idea.community.build" location="${user.home}/Tools/idea-IU-107.322/" />
<property name="target.plugin.name" value="ro.redeul.google.go" />

<taskdef name="javac2" classname="com.intellij.ant.Javac2">
<classpath>
<pathelement location="${idea.community.build}/redist/forms_rt.jar"/>
<pathelement location="${idea.community.build}/redist/javac2.jar"/>
<pathelement location="${idea.community.build}/redist/annotations.jar"/>
<fileset dir="${idea.community.build}" includes="**/*.jar" />
</classpath>

</taskdef>

<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
<!--<mkdir dir="${dist}"/>-->

</target>

<target name="compile" depends="clean,init" description="compile the source ">
<!-- Compile the java code from ${src} into ${build} -->
<javac2 srcdir="${src}" destdir="${build}" includeantruntime="false" >
<classpath>
<fileset dir="${idea.community.build}" includes="**/*.jar" />
</classpath>
<compilerarg value="-Xlint:deprecation" />
</javac2>
</target>

<target name="package" depends="compile" description="generate the distribution">
<!-- Create the distribution directory -->

<mkdir dir="${dist}"/>

<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<!--<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>-->
<jar jarfile="${dist}/${target.plugin.name}.jar">
<fileset dir="${build}" includes="**/*.*" />
<fileset dir="${src}" excludes="**/*.java" />
</jar>

</target>

<target name="clean" description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
17 changes: 16 additions & 1 deletion src/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,22 @@
<category>Custom Languages</category>

<application-components>
<!-- Add your application components here -->
<component>
<implementation-class>ro.redeul.google.go.components.GoBundledSdkDetector</implementation-class>
</component>
</application-components>

<project-components>

<!-- Add your project components here -->
<component>
<implementation-class>ro.redeul.google.go.components.GoCompilerLoader</implementation-class>
</component>

<component>
<implementation-class>ro.redeul.google.go.components.EditorTweakingComponent</implementation-class>
</component>

</project-components>

<actions>
Expand All @@ -265,6 +270,16 @@
<add-to-group group-id="NewGroup" anchor="before" relative-to-action="NewFile"/>
</group>

<group id="Go.Tools" popup="true" text="Go Tools" description="Go tools support" icon="/icons/go_16x16.png">
<action id="Go.Tools.AddGoSdk" text="Add Go Sdk Support"
description="Add Go Sdk to current module"
class="ro.redeul.google.go.tools.actions.AddGoSdkSupport">
</action>

<add-to-group group-id="ToolsMenu" anchor="last" />
</group>


</actions>

<extensions defaultExtensionNs="com.intellij">
Expand Down
3 changes: 2 additions & 1 deletion src/ro/redeul/google/go/GoBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ go.settings.completion.variables=Enable variables completion (experimental)
go.settings.build.title=Desired build system
go.sdk.configure.title=Select Go Home folder
go.settings.feature.title=Experimental features
go.settings.features.imports=Go aware imports optimizer
go.settings.features.imports=Go aware imports optimizer
go.sdk.setup=<html>aaf <a href="asdf">b</a><br/>asdf</html>
67 changes: 67 additions & 0 deletions src/ro/redeul/google/go/components/GoBundledSdkDetector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ro.redeul.google.go.components;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkModificator;
import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl;
import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil;
import org.jetbrains.annotations.NotNull;
import ro.redeul.google.go.config.sdk.GoSdkType;

import java.util.Arrays;

/**
* Author: Toader Mihai Claudiu <mtoader@gmail.com>
* <p/>
* Date: 7/26/11
* Time: 1:17 PM
*/
public class GoBundledSdkDetector implements ApplicationComponent {

@Override
public void initComponent() {
final ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();

Sdk[] sdks = jdkTable.getAllJdks();

for (Sdk sdk : sdks) {
System.out.println("Sdk: " + sdk.getName());
}

String homePath = PathManager.getHomePath() + "/bundled-go/go-sdk";

final ProjectJdkImpl newJdk;
try {
final GoSdkType goSdkType = GoSdkType.getInstance();
String newSdkName = SdkConfigurationUtil.createUniqueSdkName(goSdkType, homePath, Arrays.asList(sdks));
newJdk = new ProjectJdkImpl(newSdkName, goSdkType);
newJdk.setHomePath(homePath);
System.out.println("new jdk: " + newJdk);
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
final SdkModificator sdkModificator = newJdk.getSdkModificator();
goSdkType.setupSdkPaths(newJdk);
jdkTable.addJdk(newJdk);
}
});

} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}

@Override
public void disposeComponent() {
System.out.println("dispose");
}

@NotNull
@Override
public String getComponentName() {
return "GoBundledSdkDetector";
}
}
5 changes: 2 additions & 3 deletions src/ro/redeul/google/go/config/sdk/GoSdkData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import com.intellij.util.xmlb.XmlSerializerUtil;

/**
* Created by IntelliJ IDEA.
* User: mtoader
* Author: Toader Mihai Claudiu <mtoader@gmail.com>
* <p/>
* Date: Aug 19, 2010
* Time: 8:07:05 AM
* To change this template use File | Settings | File Templates.
*/
public class GoSdkData implements SdkAdditionalData, PersistentStateComponent<GoSdkData> {

Expand Down
Loading

0 comments on commit a9ee455

Please sign in to comment.