public String getVersion() { final SystemStatus status = applicationStatusSource.getSystemStatus(); return status.getVersion(); }
@Inject public NexusContentServlet(final RepositoryRouter repositoryRouter, final Renderer renderer, final GlobalRestApiSettings globalRestApiSettings, final ApplicationStatusSource applicationStatusSource) { this.repositoryRouter = checkNotNull(repositoryRouter); this.renderer = checkNotNull(renderer); this.globalRestApiSettings = checkNotNull(globalRestApiSettings); this.serverString = "Nexus/" + checkNotNull(applicationStatusSource).getSystemStatus().getVersion(); logger.debug("bufferSize={}, dereferenceLinks={}", BUFFER_SIZE, DEREFERENCE_LINKS); }
@Inject public VelocityRenderer(final Velocity velocity, final ApplicationStatusSource applicationStatusSource, final GlobalRestApiSettings globalRestApiSettings) { this.velocity = checkNotNull(velocity); this.applicationVersion = checkNotNull(applicationStatusSource).getSystemStatus().getVersion(); this.globalRestApiSettings = checkNotNull(globalRestApiSettings); }
/** * @return the full name of this Nexus to use in logs including App name, version and long edition if defined */ @VisibleForTesting protected final String getNexusNameForLogs(){ final StringBuilder msg = new StringBuilder(); msg.append(getSystemStatus().getAppName()); msg.append( " " ).append( getSystemStatus().getVersion() ); return msg.toString(); }
@Override public String asDiagnosticsFormat() { StringBuilder sb = new StringBuilder(); sb.append( "Nexus Version: " ); sb.append( applicationStatus.getSystemStatus().getVersion() ); sb.append( LINE_SEPERATOR ); sb.append( "Nexus Edition: " ); sb.append( applicationStatus.getSystemStatus().getEditionLong() ); sb.append( LINE_SEPERATOR ); return sb.toString(); }
protected String getSenderId() { SystemStatus status = applicationStatusSource.getSystemStatus(); if ( platformEditionShort == null || !platformEditionShort.equals( status.getEditionShort() ) || userAgentPlatformInfo == null ) { // make it "remember" to be able to detect license changes later platformEditionShort = status.getEditionShort(); userAgentPlatformInfo = new StringBuilder( "Nexus/" ).append( status.getVersion() ).append( " (" ) .append( status.getEditionShort() ).append( "; " ).append( System.getProperty( "os.name" ) ) .append( "; " ).append( System.getProperty( "os.version" ) ).append( "; " ) .append( System.getProperty( "os.arch" ) ).append( "; " ) .append( System.getProperty( "java.version" ) ).append( ") " ).toString(); } return userAgentPlatformInfo; }
protected synchronized String getUserAgentPlatformInfo() { // TODO: this is a workaround, see NXCM-363 SystemStatus status = applicationStatusSource.getSystemStatus(); if ( platformEditionShort == null || !platformEditionShort.equals( status.getEditionShort() ) || userAgentPlatformInfo == null ) { platformEditionShort = status.getEditionShort(); userAgentPlatformInfo = new StringBuilder( "Nexus/" ).append( status.getVersion() ).append( " (" ).append( status.getEditionShort() ).append( "; " ).append( System.getProperty( "os.name" ) ).append( "; " ).append( System.getProperty( "os.version" ) ).append( "; " ).append( System.getProperty( "os.arch" ) ).append( "; " ).append( System.getProperty( "java.version" ) ).append( ")" ).toString(); } return userAgentPlatformInfo; }
/** * Builds the "author" field from Nexus version. */ protected String getNexusAuthor() { return "Nexus " + getApplicationStatusSource().getSystemStatus().getVersion(); }
private byte[] renderTemplate(final String templateName) throws IOException { SystemStatus systemStatus = applicationStatusSource.getSystemStatus(); Map<String, Object> params = Maps.newHashMap(); params.put("serviceBase", "service/local"); params.put("contentBase", "content"); params.put("nexusVersion", systemStatus.getVersion()); params.put("nexusRoot", BaseUrlHolder.get()); params.put("appName", systemStatus.getAppName()); params.put("formattedAppName", systemStatus.getFormattedAppName()); boolean debugMode = isDebugMode(); params.put("debug", debugMode); List<UiContribution> contributions = Lists.newArrayList(); for (UiContributor contributor : uiContributors) { UiContribution contribution = contributor.contribute(debugMode); if (contribution.isEnabled()) { contributions.add(contribution); } } params.put("rJsContributions", contributions); params.put("buildQualifier", buildNumberService.getBuildNumber()); URL template = getClass().getResource(templateName); checkState(template != null, "Missing template: %s", templateName); log.debug("Rendering template: {}", template); String content = templateEngine.render(this, template, params); return content.getBytes(); }
public Representation getRepresentation(final Status status, final Request request, final Response response) { final HashMap<String, Object> dataModel = new HashMap<String, Object>(); final SystemStatus systemStatus = applicationStatusSource.getSystemStatus(); dataModel.put("request", request); dataModel.put("nexusVersion", systemStatus.getVersion()); dataModel.put("nexusRoot", BaseUrlHolder.get()); dataModel.put("statusCode", status.getCode()); dataModel.put("statusName", status.getName()); dataModel.put("errorDescription", StringEscapeUtils.escapeHtml(status.getDescription())); if (null != status.getThrowable()) { dataModel.put("errorStackTrace", StringEscapeUtils.escapeHtml(ExceptionUtils.getStackTrace(status.getThrowable()))); } final VelocityRepresentation representation = new VelocityRepresentation(Context.getCurrent(), "/templates/errorPageContentHtml.vm", getClass().getClassLoader(), dataModel, MediaType.TEXT_HTML); return representation; } }
protected Representation serialize(Context context, Request req, Variant variant, Object payload) throws IOException { // TEXT_HTML is requested by direct browsing (IE) // APPLICATION_XML is requested by direct browsing (FF) if (MediaType.TEXT_HTML.equals(variant.getMediaType())) { HashMap<String, Object> dataModel = new HashMap<String, Object>(); dataModel.put("listItems", sortContentListResource(((ContentListResourceResponse) payload).getData())); dataModel.put("request", req); dataModel.put("nexusVersion", applicationStatusSource.getSystemStatus().getVersion()); dataModel.put("nexusRoot", BaseUrlHolder.get()); final VelocityRepresentation representation = new VelocityRepresentation(context, "/templates/repositoryContentHtml.vm", getClass().getClassLoader(), dataModel, variant.getMediaType()); return representation; } return null; }
public Representation getRepresentation( final Status status, final Request request, final Response response ) { final HashMap<String, Object> dataModel = new HashMap<String, Object>(); dataModel.put( "request", request ); dataModel.put( "nexusVersion", nexus.getSystemStatus().getVersion() ); dataModel.put( "nexusRoot", referenceFactory.getContextRoot( request ).toString() ); dataModel.put( "statusCode", status.getCode() ); dataModel.put( "statusName", status.getName() ); dataModel.put( "errorDescription", StringEscapeUtils.escapeHtml( status.getDescription() ) ); if ( null != status.getThrowable() ) { dataModel.put( "errorStackTrace", StringEscapeUtils.escapeHtml( ExceptionUtils.getStackTrace( status.getThrowable() ) ) ); } // Load up the template, and pass in the data VelocityRepresentation representation = new VelocityRepresentation( Context.getCurrent(), "/templates/errorPageContentHtml.vm", dataModel, MediaType.TEXT_HTML ); return representation; } }
protected Representation serialize( Context context, Request req, Variant variant, Object payload ) throws IOException { // TEXT_HTML is requested by direct browsing (IE) // APPLICATION_XML is requested by direct browsing (FF) if ( MediaType.TEXT_HTML.equals( variant.getMediaType() ) ) { HashMap<String, Object> dataModel = new HashMap<String, Object>(); dataModel.put( "listItems", sortContentListResource( ( (ContentListResourceResponse) payload ).getData() ) ); dataModel.put( "request", req ); dataModel.put( "nexusVersion", getNexus().getSystemStatus().getVersion() ); dataModel.put( "nexusRoot", getContextRoot( req ).toString() ); // Load up the template, and pass in the data VelocityRepresentation representation = new VelocityRepresentation( context, "/templates/repositoryContentHtml.vm", dataModel, variant.getMediaType() ); return representation; } return null; }
/** * If request comes from a web-browser render an error page, else perform default challenge. */ @Override protected boolean sendChallenge(final ServletRequest request, final ServletResponse response) { if (browserDetector.isBrowserInitiated(request)) { HttpServletRequest httpRequest = WebUtils.toHttp(request); HttpServletResponse httpResponse = WebUtils.toHttp(response); httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); // omit WWW-Authenticate we do NOT want to have browser prompt Map<String,Object> params = ImmutableMap.of( "nexusVersion", applicationStatusSource.getSystemStatus().getVersion(), "nexusRoot", (Object)templateRenderer.getAppRootUrl(httpRequest) ); try { templateRenderer.render("/org/sonatype/nexus/web/internal/accessDeniedHtml.vm", params, httpResponse); } catch (IOException e) { throw Throwables.propagate(e); } return false; } else { return super.sendChallenge(request, response); } }
protected void upgradeNexusVersion() throws IOException { final String currentVersion = checkNotNull( applicationStatusSource.getSystemStatus().getVersion() ); final String previousVersion = getConfiguration().getNexusVersion(); if ( currentVersion.equals( previousVersion ) ) { setInstanceUpgraded( false ); } else { setInstanceUpgraded( true ); getConfiguration().setNexusVersion( currentVersion ); storeConfiguration(); } }
templatingContext.put( "nexusVersion", nexus.getSystemStatus().getVersion() );
private SyndFeedImpl createFeed() { SyndFeedImpl feed = new SyndFeedImpl(); feed.setTitle(getTitle()); feed.setDescription(getDescription()); feed.setAuthor("Nexus " + getApplicationStatusSource().getSystemStatus().getVersion()); feed.setPublishedDate(new Date()); return feed; }
protected void inspect(Event<?> evt) { if (evt instanceof NexusStartedEvent) { getFeedRecorder().addSystemEvent( FeedRecorder.SYSTEM_BOOT_ACTION, "Started Nexus (version " + getApplicationStatusSource().getSystemStatus().getVersion() + " " + getApplicationStatusSource().getSystemStatus().getEditionShort() + ")"); } else if (evt instanceof NexusStoppedEvent) { getFeedRecorder().addSystemEvent( FeedRecorder.SYSTEM_BOOT_ACTION, "Stopping Nexus (version " + getApplicationStatusSource().getSystemStatus().getVersion() + " " + getApplicationStatusSource().getSystemStatus().getEditionShort() + ")"); getFeedRecorder().shutdown(); } }
feed.setAuthor("Nexus " + getApplicationStatusSource().getSystemStatus().getVersion());
resource.setVersion( status.getVersion() );