Java Code Examples for org.rapidoid.u.U#first()

The following examples show how to use org.rapidoid.u.U#first() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractRapidoidMojo.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
protected String findMainClass(MavenProject project) {
	List<String> mainClasses = U.list();

	try {
		for (String path : project.getCompileClasspathElements()) {

			if (new File(path).isDirectory()) {
				getLog().info("Scanning classpath directory: " + path);
				scanForMainClass(path, mainClasses);

			} else if (!path.endsWith(".jar")) {
				getLog().warn("Ignoring classpath entry: " + path);
			}
		}

	} catch (Exception e) {
		throw U.rte(e);
	}

	switch (mainClasses.size()) {
		case 0:
			getLog().warn("Couldn't find the main class!");
			return null;

		case 1:
			return U.first(mainClasses);

		default:
			getLog().warn("Found multiple main classes, trying to pick the right one: " + mainClasses);
			return pickMainClass(mainClasses, project);
	}
}
 
Example 2
Source File: AbstractRapidoidMojo.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
private String pickMainClass(List<String> mainClasses, MavenProject project) {

		// the.group.id.Main
		String byGroupId = project.getGroupId() + ".Main";
		if (mainClasses.contains(byGroupId)) return byGroupId;

		List<String> namedMain = U.list();
		List<String> withGroupIdPkg = U.list();

		for (String name : mainClasses) {
			if (name.equals("Main")) return "Main";

			if (name.endsWith(".Main")) {
				namedMain.add(name);
			}

			if (name.startsWith(project.getGroupId() + ".")) {
				withGroupIdPkg.add(name);
			}
		}

		// the.group.id.foo.bar.Main
		getLog().info("Candidates by group ID: " + withGroupIdPkg);
		if (withGroupIdPkg.size() == 1) return U.single(withGroupIdPkg);

		// foo.bar.Main
		getLog().info("Candidates named Main: " + namedMain);
		if (namedMain.size() == 1) return U.single(namedMain);

		namedMain.retainAll(withGroupIdPkg);
		getLog().info("Candidates by group ID - named Main: " + namedMain);
		if (namedMain.size() == 1) return U.single(namedMain);

		// the.group.id.foo.bar.Main (the shortest name)
		withGroupIdPkg.sort((s1, s2) -> s1.length() - s2.length());
		getLog().info("Candidates by group ID - picking one with the shortest name: " + withGroupIdPkg);

		return U.first(withGroupIdPkg);
	}
 
Example 3
Source File: RoutesHandler.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
private static TableTag routesOf(Set<Route> httpRoutes, boolean withHandler) {
	List<Route> routes = U.list(httpRoutes);
	sortRoutes(routes);

	List<Object> rows = U.list();
	rows.add(tr(th("Verb"), th("Path"), th("Zone"), th("Content type"), th("MVC"), th("View name"), th("Roles"), withHandler ? th("Handler") : null));

	while (!routes.isEmpty()) {
		Route route = U.first(routes);
		List<HttpVerb> verbs = U.list(route.verb());

		Iterator<Route> it = routes.iterator();
		while (it.hasNext()) {
			Route other = it.next();

			if (route == other) {
				it.remove();
			} else if (sameTarget(route, other)) {
				verbs.add(other.verb());
				it.remove();
			}
		}

		rows.add(routeRow(route, verbs, withHandler));
	}

	return table_(rows);
}