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

Add support for Spring Boot 2.0 #4

Open
bobtiernay-okta opened this issue Apr 22, 2018 · 5 comments
Open

Add support for Spring Boot 2.0 #4

bobtiernay-okta opened this issue Apr 22, 2018 · 5 comments

Comments

@bobtiernay-okta
Copy link

This would be great for folks on the newest versions of Spring Boot.

@kakawait
Copy link
Owner

I didn't test yet. Could you please share with me any issues you get with Spring boot 2

@rome-legacy
Copy link

rome-legacy commented Feb 1, 2019

Hi Thibaud,
thx for your work. i wrote you an email regarding this problem and then i saw this open issue. so maybe i have the same problem because i'm using spring-boot 2.0.6.

i have a strange behaviour where i try to inject a @service annotated class into (sub) command.
the service is ok in my @PostConstruct function but when call() is executed its null.

@Component
@Command(name = "module", description="create module")
public class CmdModule extends HelpAwarePicocliCommand {
	private static final Logger logger = Logger.getLogger(CmdModule.class.getName());

	@Autowired
	private FileSystemService fss;
	private FileSystem fileSystem;

	@Option(names={ "-i", "--init" }, description="init new module in current directory")
	private boolean initModule;

	@Option(names={ "-d", "--disable" }, description="disable module and all commands")
	private boolean disableModule;

	@Option(names={ "-e", "--enable" }, description="enable module and all commands")
	private boolean enableModule;

	@Parameters(index="0", paramLabel="<module-name>", description="human readable module name")
	private String moduleName;

	@PostConstruct
	private void postConstruct() {
		requireNonNull(fss, "filesystem service not injected");
		fileSystem = fss.getFileSystem();
	}

	/* (non-Javadoc)
	 * @see java.util.concurrent.Callable#call()
	 */
	@Override
	public ExitStatus call() throws Exception {
		logger.info("user.dir: " + System.getProperty("user.dir")); // does it!
//		Path root = fileSystem.getPath("/");
//		DirectoryStream<Path> subdirs = Files.newDirectoryStream(root);
		fileSystem.getRootDirectories().forEach(dir -> logger.info("subdir: " + dir.toAbsolutePath().toString()));

		if (!(initModule ^ disableModule ^ enableModule) ^ (initModule && disableModule && enableModule)) {
//			throw new Exception (String.format("only one option of [%s, %s, %s] is possible", "-i", "-d", "-e"));
			throw new Exception ("only one option is possible");
		}

		if (initModule) {
			initModule(moduleName);
		}

		if (disableModule) {
			disableModule(moduleName);
		}

		if (enableModule) {
			enableModule(moduleName);
		}

		return ExitStatus.TERMINATION;
	}

	/**
	 * @param name
	 */
	private void enableModule(String name) {
		System.out.println(String.format("enable module «%s»", name));
	}

	/**
	 * @param name
	 */
	private void disableModule(String name) {
		System.out.println(String.format("disable module «%s»", name));
	}

	private void initModule(String name) {
		System.out.println(String.format("init new module «%s»", name));
		Path path = Paths.get("");
		String s = path.toAbsolutePath().toString();
//		System.out.println("current path = " + s);
	}
}

in postconstruct fss is not null and the fileSystem can be retrieved, but in fileSystem.getRootDirectories() fileSystem is null and so is fss.

any ideas?
regards

@kakawait
Copy link
Owner

kakawait commented Feb 3, 2019

@rome-legacy Ok I think I understand your issue, I'll checkout asap

@rome-legacy
Copy link

Hi @kakawait, i've tried to downgrade the libs to spring boot 1 and have the same problem. am i doing something wrong?

@kakawait
Copy link
Owner

@rome-legacy will be fixed on next version 1.0.0-beta-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants