Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stops server mode from appending 'output' to path supplied #595

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFold
*/
public DefaultJBakeConfiguration createJettyJbakeConfiguration(File sourceFolder, File destinationFolder, boolean isClearCache) throws ConfigurationException {
DefaultJBakeConfiguration configuration = (DefaultJBakeConfiguration) getConfigUtil().loadConfig(sourceFolder);
configuration.setDestinationFolder(destinationFolder);
configuration.setDestinationFolder(sourceFolder);
configuration.setClearCache(isClearCache);
configuration.setSiteHost("http://localhost:"+configuration.getServerPort());
return configuration;
Expand Down
2 changes: 1 addition & 1 deletion jbake-core/src/main/java/org/jbake/launcher/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void printUsage(Object options) {
parser.printUsage(System.out);
}

private void runServer(File path, int port) {
protected void runServer(File path, int port) {
jettyServer.run(path.getPath(), String.valueOf(port));
}

Expand Down
25 changes: 23 additions & 2 deletions jbake-core/src/test/java/org/jbake/launcher/LaunchOptionsTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package org.jbake.launcher;

import org.jbake.app.configuration.JBakeConfiguration;
import org.jbake.app.configuration.JBakeConfigurationFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kohsuke.args4j.CmdLineParser;

import java.io.File;

import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class LaunchOptionsTest {

@Spy
Main main;

@Test
public void showHelp() throws Exception {
String[] args = {"-h"};
Expand All @@ -31,13 +43,22 @@ public void runServer() throws Exception {

@Test
public void runServerWithFolder() throws Exception {
String[] args = {"-s", "/tmp"};
String path = "/tmp";
String[] args = {"-s", path};
LaunchOptions res = new LaunchOptions();
CmdLineParser parser = new CmdLineParser(res);
parser.parseArgument(args);

assertThat(res.isRunServer()).isTrue();
assertThat(res.getSource()).isEqualTo(new File("/tmp"));
assertThat(res.getSource()).isEqualTo(new File(path));

// ensures path supplied is actually used when running server
JBakeConfiguration config = new JBakeConfigurationFactory().createJettyJbakeConfiguration(res.getSource(), res.getDestination(), res.isClearCache());
// to stop server actually running when method is called
doNothing().when(main).runServer(any(File.class), any(Integer.class));
main.run(res, config);
// verify method was called with correct path
verify(main).runServer(new File(path), config.getServerPort());
}

@Test
Expand Down