Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
.classpath
.settings
.project
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ Heroku client for java web (*.war* and *.jar*) applications.

Based on heroku maven plugin (heroku-deploy submodule): https://github.com/heroku/heroku-maven-plugin

| jar files | Brief description |
| :------------ |:---------------|
| *lib/heroku-deploy-0.5.4-SNAPSHOT-jar-with-dependencies.jar* | heroku-deploy module jar with all dependencies |
| *lib/heroku-deploy-0.5.4-SNAPSHOT.jar* | heroku-deploy module jar |

#### How to run the tests?
1. set the environment property HEROKU_API_KEY with the value of a valid heroku user (something like *'X1234X5X-12X3-12X3-123X-XX1X2X3X4XX6'*)
2. run the tests
Expand Down
Binary file not shown.
Binary file removed lib/heroku-deploy-0.5.4-SNAPSHOT.jar
Binary file not shown.
8 changes: 3 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
<dependencies>
<!-- HEROKU java apps deployment -->
<dependency>
<groupId>heroku-java</groupId>
<artifactId>deploy</artifactId>
<version>0.5.4-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/lib/heroku-deploy-0.5.4-SNAPSHOT-jar-with-dependencies.jar</systemPath>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-deploy</artifactId>
<version>0.5.7</version>
</dependency>

<!-- HEROKU -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.heroku.api.Heroku;
import com.heroku.api.Addon;
import com.heroku.api.AddonChange;
Expand All @@ -25,7 +26,7 @@
*/
public class HerokuConnector
{

private String apiKey;

/**
* logs
Expand Down Expand Up @@ -59,25 +60,14 @@ public HerokuConnector()
{
logAdapter.log(Level.INFO, ">> Connecting to Heroku ...");

String apiKey = System.getenv(ENV_HEROKU_API_KEY);
if ((apiKey != null) && (!apiKey.isEmpty()))
{
try
{
_hApiClient = new HerokuAPI(apiKey);
logAdapter.log(Level.INFO, ">> Connection established: " + _hApiClient.getUserInfo().getId());
}
catch (RequestFailedException e)
{
logAdapter.log(Level.WARNING, ">> Not connected to Heroku: " + e.getMessage());
}
}
else
{
logAdapter.log(Level.WARNING, ">> Not connected to Heroku: API key is null or empty");
}
apiKey = System.getenv(ENV_HEROKU_API_KEY);
connect();
}

public HerokuConnector(String apiKey) {
this.apiKey = apiKey;
connect();
}

/**
*
Expand All @@ -88,25 +78,31 @@ public HerokuConnector(String login, String passwd)
{
logAdapter.log(Level.INFO, ">> Connecting to Heroku ...");

String apiKey = HerokuAPI.obtainApiKey(login, passwd);
if ((apiKey != null) && (!apiKey.isEmpty()))
{
try
{
_hApiClient = new HerokuAPI(apiKey);
logAdapter.log(Level.INFO, ">> Connection established: " + _hApiClient.getUserInfo().getId());
}
catch (RequestFailedException e)
{
logAdapter.log(Level.WARNING, ">> Not connected to Heroku: " + e.getMessage());
}
}
else
{
logAdapter.log(Level.WARNING, ">> Not connected to Heroku: API key is null or empty");
}
apiKey = HerokuAPI.obtainApiKey(login, passwd);
connect();
}

private void connect() {
if ((apiKey != null) && (!apiKey.isEmpty()))
{
try
{
_hApiClient = new HerokuAPI(apiKey);
logAdapter.log(Level.INFO, ">> Connection established: " + _hApiClient.getUserInfo().getId());
return;
}
catch (RequestFailedException e)
{
logAdapter.log(Level.WARNING, ">> Not connected to Heroku: " + e.getMessage());
throw new RuntimeException("Not connected to Heroku: " + e.getMessage(), e);
}
}
else
{
logAdapter.log(Level.WARNING, ">> Not connected to Heroku: API key is null or empty");
throw new RuntimeException("Not connected to Heroku: API key is null or empty");
}
}


/**
*
Expand Down Expand Up @@ -190,7 +186,7 @@ public boolean deployJavaWebApp(String applicationName, String warFile)
String webappRunnerVersion = DEFAULT_WEBAPP_RUNNER_VERSION;
String webappRunnerUrl = String.format(WEBAPP_RUNNER_URL_FORMAT, webappRunnerVersion, webappRunnerVersion);

DeployWar deployWarApp = new DeployWar(applicationName, new File(warFile), new URL(webappRunnerUrl));
DeployWar deployWarApp = new DeployWar(applicationName, new File(warFile), new URL(webappRunnerUrl), apiKey);
deployWarApp.deploy(includes, new HashMap<String, String>(), jdkUrl == null ? jdkVersion : jdkUrl, stack, slugFileName);

logAdapter.log(Level.INFO, ">> Application deployed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@ public class HerokuConnectorTest
{


// logs
//////////////////////////////////////////////////////////////// logs
private static final Logger logAdapter = Logger.getLogger(HerokuConnectorTest.class.getName());

// heroku client
public HerokuConnector hclient;

// global values for tests
public static final String APP_NAME = "app-tests-wabapp-roi2";
public static final String APP_WAR_PATH = "C:/temporal/webapp.war";
public static final String APP_WAR_PATH = "D:/uploads/SampleApp1.war";
public static final String ADDON_CLEARDB_IGNITE = "cleardb:ignite";
public static final String ENV_CLEARDB = "CLEARDB_DATABASE_URL";


@Before
public void setUp() throws Exception
{
hclient = new HerokuConnector();
String apiKey = System.getenv("API_KEY");
hclient = new HerokuConnector(apiKey);
}


Expand Down Expand Up @@ -72,15 +73,13 @@ public void testDeleteApp()
assertTrue(!hclient.appExists(APP_NAME));
}

/*
@Test
public void testDeployApp()
{
assertTrue(hclient.deployJavaWebApp(APP_NAME, APP_WAR_PATH));
}
*/

@Test
// @Test
public void testDeployJavaWebAppWithDataBase()
{
hclient.deployJavaWebAppWithDataBase(APP_NAME, APP_WAR_PATH, ADDON_CLEARDB_IGNITE);
Expand Down